Managing HMR State Preservation with Circular Dependencies
0 reputation · 06 Jan 2022, 13:18 UTC
Vite uses a dependency graph to manage Hot Module Replacement (HMR), allowing modules to opt-in to updates via import.meta.hot. When a module is updated, Vite attempts to invalidate only the affected branch of the graph to avoid a full page reload.
A challenge arises when circular dependencies exist within the module graph. In these scenarios, the HMR boundary mechanism may struggle to determine the precise point of invalidation, potentially leading to update loops or the failure of a module to refresh its state correctly.
Assuming Vite v5.x, what is the documented behavior for HMR propagation when a circular dependency crosses an hmr.accept boundary? Does the current invalidation logic prioritize the parent boundary or the circular link during the update bubble-up process?