feat(hmr): check boundary outside the circular imports#21624
feat(hmr): check boundary outside the circular imports#21624sapphi-red wants to merge 2 commits intomainfrom
Conversation
| } else if (traversedModules.size > 10) { | ||
| environment.logger.warn( | ||
| colors.yellow( | ||
| `hmr boundary skipped due to circular imports, ` + | ||
| `${traversedModules.size} modules will re-execute. ` + | ||
| `To debug and break the circular import, use ${colors.dim('`vite --debug hmr`')} to log the circular import path.`, | ||
| ), | ||
| { timestamp: true }, | ||
| ) | ||
| } |
There was a problem hiding this comment.
Can you explain this part and why this PR is removing the warning on the client-side? isWithinCircularImports was introduced for #15118 so we reload the page in case the circular modules cannot recover in the client, does that not happen in this PR anymore?
There was a problem hiding this comment.
It doesn't happen anymore. If there's a circular import, this PR will make Vite to pick a boundary outside of the circular import. If there's no boundary outside the circular import, it'll trigger a reload. So there won't be a client side error caused by circular imports.
There was a problem hiding this comment.
I see. So a minor difference I think is that as you mentioned, if:
- There's a boundary in a circular import
- There's no boundary outside of the circular import
It will now always reload the page. Previously it would try doing an inner boundary HMR first, before falling back to reload.
So, I don't know how Linear's import structure works, but if they have something like index.html -> main.ts -> App.tsx -> ... -> App.tsx, then I assume this will now always trigger a reload, which isn't something they want to happen.
I'm happy to try the force reload instead so that the execution order is always correct, but if we have a request for the previous behavior again, maybe we need to bring the handling back.
When a HMR boundary is detected within a circular import chain, skip it and continue propagation outward to find a boundary outside the chain.
graph LR B["b.js"] -->|import| C["c.js (boundary)"] C -->|import| B A["a.js (boundary)"] -->|import| BWhen
c.jsis changed,c.jsis now ignored anda.jsis now treated as the boundary.fixes #16580
fixes #18217