Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Safely retrieve router, improve page reload logic #74209

Open
wants to merge 1 commit into
base: canary
Choose a base branch
from

Conversation

gurkerl83
Copy link
Contributor

This PR improves the hot module reloading (HMR) logic in the dev client by:

  • Safe Router Retrieval: Uses optional chaining (window.next?.router) to prevent errors if the router is uninitialized.
  • Enhanced Error Page Handling: Ensures the client reloads when on /404 or /_error pages, addressing cases where page additions/removals can't be reliably matched to the current path.
  • Improved Reload Logic: Checks if the current page is added or removed and triggers a reload accordingly to keep the client state up-to-date.
  • Updated Comments: Clarifies the conditions under which reloads occur, especially when on error pages.

These changes make the HMR process more robust and prevent potential runtime issues.

Closes #71974

This PR improves the hot module reloading (HMR) logic in the dev client by:

- Safe Router Retrieval: Uses optional chaining (window.next?.router) to prevent errors if the router is uninitialized.
- Enhanced Error Page Handling: Ensures the client reloads when on /404 or /_error pages, addressing cases where page additions/removals can't be reliably matched to the current path.
- Improved Reload Logic: Checks if the current page is added or removed and triggers a reload accordingly to keep the client state up-to-date.
- Updated Comments: Clarifies the conditions under which reloads occur, especially when on error pages.

These changes make the HMR process more robust and prevent potential runtime issues.

Closes vercel#71974
@ijjk
Copy link
Member

ijjk commented Dec 21, 2024

Allow CI Workflow Run

  • approve CI run for commit: 8c6bdf9

Note: this should only be enabled once the PR is ready to go and can only be enabled by a maintainer

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Page Router - Turbopack HMR Warning: window.next.router undefined during appIsrManifest event
2 participants