Open gurkerl83 opened 1 week ago
⬆️ same problem
Edit by maintainer bot: Comment was automatically minimized because it was considered unhelpful. (If you think this was by mistake, let us know). Please only comment if it adds context to the issue. If you want to express that you have the same problem, use the upvote 👍 on the issue description or subscribe to the issue for updates. Thanks!
Link to the code that reproduces this issue
https://github.com/gurkerl83/next-turbo-dynamic-import
To Reproduce
The following reproducer was create for another ticket. The HMR problem is observable even in this demonstrator, so I hope this is OK for reuse.
The reproduction case was originally created to address a different issue. To use it for this problem, please comment out both the import and render of the ComponentNamedImportWithIssue component.
Install dependencies using pnpm:
Current vs. Expected behavior
Current behavior: When starting the application with Turbopack in development mode, a TypeError occurs due to window.next.router being undefined during HMR events, specifically during the appIsrManifest action. This results in console warnings and may disrupt the development workflow.
Expected behavior: The application should start without any TypeError or HMR warnings. Hot Module Replacement (HMR) events should not cause errors even if window.next.router is not yet initialized.
Provide environment information
Which area(s) are affected? (Select all that apply)
Pages Router, Turbopack
Which stage(s) are affected? (Select all that apply)
next dev (local)
Additional context
In the Next.js source code, there are two distinct hot-reloader-client implementations: one for the Page Router and another for the App Router.
The Page Router variant includes a custom event handler,
customHmrEventHandler
, which is responsible for handling specific hot-reload events. This functionality is implemented in the following code snippet to address the issue effectively.packages/next/src/client/dev/hot-middleware-client.ts
Note: This issue may not be detectable in the App Router because the event handler in question is not utilized there. The reproduction case specifically relies on the Page Router.