Skip to content
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

vite-node --watch duplicates import.meta.hot.data self-accepting module #6823

Open
6 tasks done
vanaigr opened this issue Oct 30, 2024 · 1 comment
Open
6 tasks done

Comments

@vanaigr
Copy link
Contributor

vanaigr commented Oct 30, 2024

Describe the bug

For a self-accepting module, saving an unused html file in the same directory reloads the module, but doesn't preserve its import.meta.hot.data.

Triggering a hot update afterwards (by saving a dependency module) leads to the module being reloaded and accept()ed twice with different import.meta.hot.data.

Reproduction

https://stackblitz.com/edit/vitest-dev-vitest-78iwey

Running vite-node -c ./src/vite.config.js --watch ./src/index.mjs prints:

setup   0       at      18:24:51.585

After changing inner.mjs, we can see that index.mjs is reloaded, and import.meta.hot.data is preserved:

setup   1       at      18:25:26.230
accept  1       at      18:25:26.232
[vite-node] hot updated: /home/projects/vitest-dev-vitest-78iwey/src/index.mjs
setup   2       at      18:25:28.222
accept  2       at      18:25:28.223
[vite-node] hot updated: /home/projects/vitest-dev-vitest-78iwey/src/index.mjs
setup   3       at      18:25:30.310
accept  3       at      18:25:30.311
[vite-node] hot updated: /home/projects/vitest-dev-vitest-78iwey/src/index.mjs

But if we now change unused.html, index.mjs is reloaded as if for the first time:

setup   0       at      18:25:35.274

If now we change inner.mjs again, we see both modules are reloaded and import.meta.hot.accept() runs for both:

setup   4       at      18:25:47.449
setup   1       at      18:25:47.450
accept  4       at      18:25:47.450
[vite-node] hot updated: /home/projects/vitest-dev-vitest-78iwey/src/index.mjs
accept  1       at      18:25:47.451
[vite-node] hot updated: ./src/index.mjs

Full output:

setup   0       at      18:24:51.585
setup   1       at      18:25:26.230
accept  1       at      18:25:26.232
[vite-node] hot updated: /home/projects/vitest-dev-vitest-78iwey/src/index.mjs
setup   2       at      18:25:28.222
accept  2       at      18:25:28.223
[vite-node] hot updated: /home/projects/vitest-dev-vitest-78iwey/src/index.mjs
setup   3       at      18:25:30.310
accept  3       at      18:25:30.311
[vite-node] hot updated: /home/projects/vitest-dev-vitest-78iwey/src/index.mjs
setup   0       at      18:25:35.274
setup   4       at      18:25:47.449
setup   1       at      18:25:47.450
accept  4       at      18:25:47.450
[vite-node] hot updated: /home/projects/vitest-dev-vitest-78iwey/src/index.mjs
accept  1       at      18:25:47.451
[vite-node] hot updated: ./src/index.mjs

System Info

npx envinfo --system --npmPackages '{vitest,@vitest/*,vite,@vitejs/*,vite-node}' --binaries --browsers

Output:

  System:
    OS: Linux 5.0 undefined
    CPU: (8) x64 Intel(R) Core(TM) i9-9880H CPU @ 2.30GHz
    Memory: 0 Bytes / 0 Bytes
    Shell: 1.0 - /bin/jsh
  Binaries:
    Node: 18.20.3 - /usr/local/bin/node
    Yarn: 1.22.19 - /usr/local/bin/yarn
    npm: 10.2.3 - /usr/local/bin/npm
    pnpm: 8.15.6 - /usr/local/bin/pnpm
  npmPackages:
    vite: latest => 5.4.10 
    vite-node: latest => 2.1.4 

Used Package Manager

npm

Validations

@vanaigr
Copy link
Contributor Author

vanaigr commented Oct 30, 2024

May be related. If I add this to index.mjs:

import.meta.hot.on("vite:beforeUpdate", () => {
    console.log("update");
})

With each change, more and more "update" messages are printed:

setup   0       at      19:07:57.390
update
setup   1       at      19:07:59.981
accept  1       at      19:07:59.981
[vite-node] hot updated: /home/projects/vitest-dev-vitest-78iwey/src/index.mjs
update
update
setup   2       at      19:08:02.336
accept  2       at      19:08:02.336
[vite-node] hot updated: /home/projects/vitest-dev-vitest-78iwey/src/index.mjs
update
update
update
setup   3       at      19:08:03.939
accept  3       at      19:08:03.940
[vite-node] hot updated: /home/projects/vitest-dev-vitest-78iwey/src/index.mjs
update
update
update
update
setup   4       at      19:08:05.275
accept  4       at      19:08:05.275
[vite-node] hot updated: /home/projects/vitest-dev-vitest-78iwey/src/index.mjs
update
update
update
update
update
setup   5       at      19:08:06.459
accept  5       at      19:08:06.459
[vite-node] hot updated: /home/projects/vitest-dev-vitest-78iwey/src/index.mjs
update
update
update
update
update
update
setup   6       at      19:08:08.053
accept  6       at      19:08:08.054
[vite-node] hot updated: /home/projects/vitest-dev-vitest-78iwey/src/index.mjs
update
update
update
update
update
update
update
setup   7       at      19:08:09.159
accept  7       at      19:08:09.159
[vite-node] hot updated: /home/projects/vitest-dev-vitest-78iwey/src/index.mjs
update
update
update
update
update
update
update
update
setup   8       at      19:08:10.272
accept  8       at      19:08:10.272
[vite-node] hot updated: /home/projects/vitest-dev-vitest-78iwey/src/index.mjs

I don't know if this is intended behavior, but I assume it's not, given #2792.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

2 participants