You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Modules PageA, PageB, ... define pages with their parameters and render links to other pages.
When Links is changed, HMR posts js-update with Links, which is fine.
However, when PageA is changed, HMR posts js-update with PageA, which fails with ReferenceError: Cannot access 'UsersPage' before initialization. (The exception is thrown because PageA imports the invalidated module Links, which references to PageA that has not yet been initialized.)
Suggested solution
The solution is to change HMR so that it imports modules in the same order as they were initially imported.
For the example above:
When PageA is changed, send js-update with Links instead of PageA.
Alternative
No response
Additional context
I found the following PRs that attempts to address HMR issues with circular imports:
Description
As a developer migrating to Vite I want HMR to work with circular imports.
HMR currently fallbacks to full-reload when an exception is thrown during import:
vite/packages/vite/src/client/client.ts
Lines 159 to 167 in 2bc5d3d
This happens when modules with the
isWithinCircularImport
flag are imported in a different than the original order.Example:
Main
importsLinks
Links
importsPageA
,PageB
, ...PageA
importsLinks
PageB
importsLinks
Simplified content of the
Links
module:Modules
PageA
,PageB
, ... define pages with their parameters and render links to other pages.When
Links
is changed, HMR postsjs-update
withLinks
, which is fine.However, when
PageA
is changed, HMR postsjs-update
withPageA
, which fails withReferenceError: Cannot access 'UsersPage' before initialization
. (The exception is thrown becausePageA
imports the invalidated moduleLinks
, which references toPageA
that has not yet been initialized.)Suggested solution
The solution is to change HMR so that it imports modules in the same order as they were initially imported.
For the example above:
When
PageA
is changed, sendjs-update
withLinks
instead ofPageA
.Alternative
No response
Additional context
I found the following PRs that attempts to address HMR issues with circular imports:
And the following issues:
Validations
The text was updated successfully, but these errors were encountered: