question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

HMR causes modules to be re-evaluated due to circular imports

See original GitHub issue

⚠️ IMPORTANT ⚠️ Please do not ignore this template. If you do, your issue will be closed immediately.

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 https://github.com/vitejs/vite/blob/4396057abd69bf55dfc8976f6feaddf6042031a5/packages/vite/src/node/server/hmr.ts#L237

It would be nice if this behaviour was configurable.

Reproduction

https://github.com/nowylie/vite-2-repro

npm ci
npm run vite
  1. Open the repro page in the browser
  2. Open the JS console in the dev tools
  3. Save src/dep.js to trigger a HMR update
  4. Note that main.js is re-evaluated

System Info

  • vite version: 2.0.4
  • Operating System: macOS 11.2
  • Node version: 14.16.0
  • Package manager (npm/yarn/pnpm) and version: npm 6.14.11

Issue Analytics

  • State:closed
  • Created 3 years ago
  • Comments:5 (1 by maintainers)

github_iconTop GitHub Comments

2reactions
anncwbcommented, Mar 11, 2021

@anncwb no solution yet.

As I mentioned, our circular dependencies are by design.

For accidental/unnecessary circular dependencies, I’ve had success in the past using madge to track them down.

I reopened an issue, wait to see the author’s reply

0reactions
nowyliecommented, Mar 8, 2021

@anncwb no solution yet.

As I mentioned, our circular dependencies are by design.

For accidental/unnecessary circular dependencies, I’ve had success in the past using madge to track them down.

Read more comments on GitHub >

github_iconTop Results From Across the Web

Avoiding Circular Imports in Python | by André Menck - Medium
The reason why circular imports in Python result in errors has been explained by ... initialized module 'child' (most likely due to a...
Read more >
Circular import dependency in Python - Stack Overflow
Circular Dependencies due to Type Hints. With type hints, there are more opportunities for creating circular imports. Fortunately ...
Read more >
HAZARDOUS MATERIALS REGULATIONS - GovInfo
Requirements in the HMR apply to each person who offers a hazardous material for transportation in commerce, causes a hazardous material to be...
Read more >
49 CFR Part 171 -- General Information, Regulations ... - eCFR
Requirements in the HMR apply to each person who offers a hazardous material for transportation in commerce, causes a hazardous material to be...
Read more >
Python Circular Imports Module: Solving Circular Import Problem
Circular imports are created because of the bad coding design and implementation-related logical anomalies. Here is a situation shown using three separate ...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found