-
-
Notifications
You must be signed in to change notification settings - Fork 6.2k
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
HMR causes modules to be re-evaluated due to circular imports #2314
Comments
This is expected behavior. If there are circular imports, the only way to ensure correctness is to invalidate all modules in the chain. If you want to avoid it, consider refactor your code to avoid circular imports. |
Thanks @yyx990803 for taking the time to look at this issue! I can understand that this is expected behaviour but had hoped it might be possible for there to be a configuration option to disable it. For a bit more context, I used Vite 1 to develop some basic HMR support for Overture.js which we use to develop the front-end for Fastmail. Overture makes reasonably heavy usage of Classes and Inheritance. This makes supporting HMR a bit difficult since updated modules export new class definitions and break Within our app, we have a central router module that handles routing and dynamically loading other parts of the app. The router module also exports some global state that other modules reference. This is where our circular dependencies come from. I think this is a sound design. However this doesn't work well with Vite's new behaviour. Since parent modules are invalidated, an update in one of our View modules causes the router module to be invalidated and from there a large portion of the app is invalidated (since the router module is so central). Is there any chance that this behaviour could be made configurable so that we can continue to use Vite? |
@nowylie |
Describe the bug
In Vite 1, when a module is updated only that module is re-evaluated in the browser.
In Vite 2, when a module is updated all modules that depend on the updated module are invalidated and have their import path updated, causing the browser to re-evaluate the modules if they're in the dependency tree of the updated module (due to circular dependencies). Marking modules with
import.meta.hot.decline()
doesn't appear to make any difference.Specifically the issue is at
vite/packages/vite/src/node/server/hmr.ts
Line 237 in 4396057
It would be nice if this behaviour was configurable.
Reproduction
https://github.com/nowylie/vite-2-repro
src/dep.js
to trigger a HMR updatemain.js
is re-evaluatedSystem Info
vite
version:2.0.4
macOS 11.2
14.16.0
npm 6.14.11
The text was updated successfully, but these errors were encountered: