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

Full page reload instead of HMR when file that was referenced before is renamed or deleted after being dereferenced #10710

Closed
7 tasks done
dariocravero opened this issue Oct 29, 2022 · 2 comments

Comments

@dariocravero
Copy link

Describe the bug

What I'm doing:

  • If I rename or delete a file and another file imported it in the past, Vite does a full reload even if the file isn't referenced anymore.

What I expect is:

  • That Vite ignores the change since the file isn't referenced from anywhere.

What actually happens is:

  • Vite does a full page reload.

Reproduction

https://github.com/dariocravero/vite-page-reload-issue

Steps to reproduce

The repo provided is a new vite project created from npm create vite@latest with a new src/Test.js exporting a function which is imported in src/App.jsx.

Steps:

  • comment out import Test from './Test.js'; in App.jsx
  • rename Test.js to Test2.js: the vite app will reload
  • reload the site and rename Test2.js to Test.js: the vite app ignores the change
  • uncomment import Test from './Test.js'; in App.jsx
  • rename Test.js to Test2.js: the vite app will reload

System Info

System:
    OS: macOS 13.0
    CPU: (16) x64 Intel(R) Core(TM) i9-9880H CPU @ 2.30GHz
    Memory: 17.17 GB / 32.00 GB
    Shell: 3.2.57 - /bin/bash
  Binaries:
    Node: 16.14.2 - ~/n/bin/node
    Yarn: 1.22.4 - ~/.yarn/bin/yarn
    npm: 8.5.5 - /usr/local/bin/npm
    Watchman: 2022.08.15.00 - /usr/local/bin/watchman
  Browsers:
    Brave Browser: 107.1.45.113
    Firefox: 103.0.2
    Safari: 16.1
  npmPackages:
    @vitejs/plugin-react: ^2.2.0 => 2.2.0 
    vite: ^3.2.0 => 3.2.1

Used Package Manager

npm

Logs

Click to expand!
> vite-project@0.0.0 dev /Users/dario/opensource/vite-project
> vite --debug

  vite:config bundled config file loaded in 225.25ms +0ms
  vite:esbuild init tsconfck (root: /Users/dario/opensource/vite-project) +0ms
  vite:esbuild init tsconfck (root: /Users/dario/opensource/vite-project) +1ms
  vite:esbuild init tsconfck end +1ms
  vite:esbuild init tsconfck end +0ms
  vite:config using resolved config: {
  vite:config   plugins: [
  vite:config     'vite:pre-alias',
  vite:config     'alias',
  vite:config     'vite:react-babel',
  vite:config     'vite:react-refresh',
  vite:config     'vite:react-jsx',
  vite:config     'vite:modulepreload-polyfill',
  vite:config     'vite:optimized-deps',
  vite:config     'vite:resolve',
  vite:config     'vite:html-inline-proxy',
  vite:config     'vite:css',
  vite:config     'vite:esbuild',
  vite:config     'vite:json',
  vite:config     'vite:wasm-helper',
  vite:config     'vite:worker',
  vite:config     'vite:asset',
  vite:config     'vite:wasm-fallback',
  vite:config     'vite:define',
  vite:config     'vite:css-post',
  vite:config     'vite:worker-import-meta-url',
  vite:config     'vite:asset-import-meta-url',
  vite:config     'vite:dynamic-import-vars',
  vite:config     'vite:import-glob',
  vite:config     'vite:client-inject',
  vite:config     'vite:import-analysis'
  vite:config   ],
  vite:config   optimizeDeps: {
  vite:config     disabled: 'build',
  vite:config     force: undefined,
  vite:config     include: [ 'react/jsx-runtime', 'react/jsx-dev-runtime', 'react' ],
  vite:config     esbuildOptions: { preserveSymlinks: false }
  vite:config   },
  vite:config   server: {
  vite:config     preTransformRequests: true,
  vite:config     middlewareMode: false,
  vite:config     fs: { strict: true, allow: [Array], deny: [Array] }
  vite:config   },
  vite:config   resolve: {
  vite:config     mainFields: [ 'module', 'jsnext:main', 'jsnext' ],
  vite:config     browserField: true,
  vite:config     conditions: [],
  vite:config     extensions: [
  vite:config       '.mjs',  '.js',
  vite:config       '.mts',  '.ts',
  vite:config       '.jsx',  '.tsx',
  vite:config       '.json'
  vite:config     ],
  vite:config     dedupe: [ 'react', 'react-dom' ],
  vite:config     preserveSymlinks: false,
  vite:config     alias: [ [Object], [Object] ]
  vite:config   },
  vite:config   configFile: '/Users/dario/opensource/vite-project/vite.config.js',
  vite:config   configFileDependencies: [ '/Users/dario/opensource/vite-project/vite.config.js' ],
  vite:config   inlineConfig: {
  vite:config     root: undefined,
  vite:config     base: undefined,
  vite:config     mode: undefined,
  vite:config     configFile: undefined,
  vite:config     logLevel: undefined,
  vite:config     clearScreen: undefined,
  vite:config     optimizeDeps: { force: undefined },
  vite:config     server: {}
  vite:config   },
  vite:config   root: '/Users/dario/opensource/vite-project',
  vite:config   base: '/',
  vite:config   publicDir: '/Users/dario/opensource/vite-project/public',
  vite:config   cacheDir: '/Users/dario/opensource/vite-project/node_modules/.vite',
  vite:config   command: 'serve',
  vite:config   mode: 'development',
  vite:config   ssr: {
  vite:config     format: 'esm',
  vite:config     target: 'node',
  vite:config     optimizeDeps: { disabled: true, esbuildOptions: [Object] }
  vite:config   },
  vite:config   isWorker: false,
  vite:config   mainConfig: null,
  vite:config   isProduction: false,
  vite:config   build: {
  vite:config     target: [ 'es2020', 'edge88', 'firefox78', 'chrome87', 'safari13' ],
  vite:config     cssTarget: [ 'es2020', 'edge88', 'firefox78', 'chrome87', 'safari13' ],
  vite:config     outDir: 'dist',
  vite:config     assetsDir: 'assets',
  vite:config     assetsInlineLimit: 4096,
  vite:config     cssCodeSplit: true,
  vite:config     sourcemap: false,
  vite:config     rollupOptions: {},
  vite:config     minify: 'esbuild',
  vite:config     terserOptions: {},
  vite:config     write: true,
  vite:config     emptyOutDir: null,
  vite:config     copyPublicDir: true,
  vite:config     manifest: false,
  vite:config     lib: false,
  vite:config     ssr: false,
  vite:config     ssrManifest: false,
  vite:config     reportCompressedSize: true,
  vite:config     chunkSizeWarningLimit: 500,
  vite:config     watch: null,
  vite:config     commonjsOptions: { include: [Array], extensions: [Array] },
  vite:config     dynamicImportVarsOptions: { warnOnError: true, exclude: [Array] },
  vite:config     modulePreload: { polyfill: true }
  vite:config   },
  vite:config   preview: {
  vite:config     port: undefined,
  vite:config     strictPort: undefined,
  vite:config     host: undefined,
  vite:config     https: undefined,
  vite:config     open: undefined,
  vite:config     proxy: undefined,
  vite:config     cors: undefined,
  vite:config     headers: undefined
  vite:config   },
  vite:config   env: { BASE_URL: '/', MODE: 'development', DEV: true, PROD: false },
  vite:config   assetsInclude: [Function: assetsInclude],
  vite:config   logger: {
  vite:config     hasWarned: false,
  vite:config     info: [Function: info],
  vite:config     warn: [Function: warn],
  vite:config     warnOnce: [Function: warnOnce],
  vite:config     error: [Function: error],
  vite:config     clearScreen: [Function: clearScreen],
  vite:config     hasErrorLogged: [Function: hasErrorLogged]
  vite:config   },
  vite:config   packageCache: Map(0) {},
  vite:config   createResolver: [Function: createResolver],
  vite:config   worker: {
  vite:config     format: 'iife',
  vite:config     plugins: [
  vite:config       'vite:pre-alias',
  vite:config       'alias',
  vite:config       'vite:modulepreload-polyfill',
  vite:config       'vite:optimized-deps',
  vite:config       'vite:resolve',
  vite:config       'vite:html-inline-proxy',
  vite:config       'vite:css',
  vite:config       'vite:esbuild',
  vite:config       'vite:json',
  vite:config       'vite:wasm-helper',
  vite:config       'vite:worker',
  vite:config       'vite:asset',
  vite:config       'vite:wasm-fallback',
  vite:config       'vite:define',
  vite:config       'vite:css-post',
  vite:config       'vite:worker-import-meta-url',
  vite:config       'vite:asset-import-meta-url',
  vite:config       'vite:dynamic-import-vars',
  vite:config       'vite:import-glob',
  vite:config       'vite:client-inject',
  vite:config       'vite:import-analysis'
  vite:config     ],
  vite:config     rollupOptions: {},
  vite:config     getSortedPlugins: [Function: getSortedPlugins],
  vite:config     getSortedPluginHooks: [Function: getSortedPluginHooks]
  vite:config   },
  vite:config   appType: 'spa',
  vite:config   experimental: { importGlobRestoreExtension: false, hmrPartialAccept: false },
  vite:config   getSortedPlugins: [Function: getSortedPlugins],
  vite:config   getSortedPluginHooks: [Function: getSortedPluginHooks]
  vite:config } +6ms
  vite:deps Hash is consistent. Skipping. Use --force to override. +0ms

  VITE v3.2.1  ready in 379 ms

  ➜  Local:   http://localhost:5173/
  ➜  Network: use --host to expose
  vite:html-fallback Rewriting GET / to /index.html +0ms
  vite:time 21.20ms /index.html +0ms
  vite:resolve 1.83ms /@vite/client -> /Users/dario/opensource/vite-project/node_modules/vite/dist/client/client.mjs +0ms
  vite:resolve 0.37ms /src/main.jsx -> /Users/dario/opensource/vite-project/src/main.jsx +4ms
  vite:load 3.26ms [fs] /@vite/client +0ms
  vite:load 18.36ms [fs] /src/main.jsx +18ms
  vite:resolve 0.45ms @vite/env -> /Users/dario/opensource/vite-project/node_modules/vite/dist/client/env.mjs +85ms
  vite:resolve 0.19ms /node_modules/vite/dist/client/env.mjs -> /Users/dario/opensource/vite-project/node_modules/vite/dist/client/env.mjs +0ms
  vite:import-analysis 4.09ms [1 imports rewritten] node_modules/vite/dist/client/client.mjs +0ms
  vite:transform 83.90ms /@vite/client +0ms
  vite:time 93.34ms /@vite/client +117ms
  vite:resolve 0.27ms react -> /Users/dario/opensource/vite-project/node_modules/.vite/deps/react.js?v=fb556155 +4ms
  vite:resolve 0.13ms /node_modules/.vite/deps/react.js?v=fb556155 -> /Users/dario/opensource/vite-project/node_modules/.vite/deps/react.js?v=fb556155 +1ms
  vite:import-analysis /node_modules/.vite/deps/react.js?v=fb556155 needs interop +4ms
  vite:resolve 0.09ms react-dom/client -> /Users/dario/opensource/vite-project/node_modules/.vite/deps/react-dom_client.js?v=fb556155 +2ms
  vite:resolve 0.05ms /node_modules/.vite/deps/react-dom_client.js?v=fb556155 -> /Users/dario/opensource/vite-project/node_modules/.vite/deps/react-dom_client.js?v=fb556155 +0ms
  vite:import-analysis /node_modules/.vite/deps/react-dom_client.js?v=fb556155 needs interop +2ms
  vite:resolve 2.04ms ./App -> /Users/dario/opensource/vite-project/src/App.jsx +3ms
  vite:resolve 0.16ms /src/App.jsx -> /Users/dario/opensource/vite-project/src/App.jsx +0ms
  vite:resolve 0.17ms ./index.css -> /Users/dario/opensource/vite-project/src/index.css +1ms
  vite:resolve 0.21ms /src/index.css -> /Users/dario/opensource/vite-project/src/index.css +0ms
  vite:resolve 0.03ms react/jsx-dev-runtime -> react/jsx-dev-runtime +0ms
  vite:resolve 0.12ms react/jsx-dev-runtime -> null +1ms
  vite:import-analysis 8.44ms [5 imports rewritten] src/main.jsx +5ms
  vite:transform 81.21ms /src/main.jsx +14ms
  vite:optimize-deps load /Users/dario/opensource/vite-project/node_modules/.vite/deps/react.js +0ms
  vite:optimize-deps load /Users/dario/opensource/vite-project/node_modules/.vite/deps/react-dom_client.js +0ms
  vite:load 0.02ms [plugin] react/jsx-dev-runtime +82ms
  vite:resolve 0.07ms react/jsx-dev-runtime -> /Users/dario/opensource/vite-project/node_modules/.vite/deps/react_jsx-dev-runtime.js?v=fb556155 +5ms
  vite:resolve 0.05ms /node_modules/.vite/deps/react_jsx-dev-runtime.js?v=fb556155 -> /Users/dario/opensource/vite-project/node_modules/.vite/deps/react_jsx-dev-runtime.js?v=fb556155 +0ms
  vite:import-analysis /node_modules/.vite/deps/react_jsx-dev-runtime.js?v=fb556155 needs interop +5ms
  vite:import-analysis 0.79ms [1 imports rewritten] react/jsx-dev-runtime +1ms
  vite:transform 0.92ms react/jsx-dev-runtime +3ms
  vite:optimize-deps load /Users/dario/opensource/vite-project/node_modules/.vite/deps/react_jsx-dev-runtime.js +2ms
  vite:load 0.02ms [plugin] /@react-refresh +5ms
  vite:import-analysis 1.40ms [no imports] /@react-refresh +5ms
  vite:transform 2.24ms /@react-refresh +5ms
  vite:time 2.72ms /@react-refresh +21ms
  vite:load 21.08ms [fs] /node_modules/vite/dist/client/env.mjs +2ms
  vite:load 8.02ms [plugin] /node_modules/.vite/deps/react.js?v=fb556155 +1ms
  vite:resolve 0.17ms ./chunk-MQMBJ7LP.js -> /Users/dario/opensource/vite-project/node_modules/.vite/deps/chunk-MQMBJ7LP.js?v=fb556155 +8ms
  vite:resolve 0.06ms /node_modules/.vite/deps/chunk-MQMBJ7LP.js?v=fb556155 -> /Users/dario/opensource/vite-project/node_modules/.vite/deps/chunk-MQMBJ7LP.js?v=fb556155 +0ms
  vite:import-analysis 0.69ms [1 imports rewritten] node_modules/.vite/deps/react.js?v=fb556155 +2ms
  vite:transform 1.08ms /node_modules/.vite/deps/react.js?v=fb556155 +2ms
  vite:optimize-deps load /Users/dario/opensource/vite-project/node_modules/.vite/deps/chunk-MQMBJ7LP.js +8ms
  vite:load 9.68ms [fs] /src/App.jsx +2ms
  vite:load 37.19ms [fs] /src/index.css +27ms
  vite:load 37.47ms [plugin] /node_modules/.vite/deps/react_jsx-dev-runtime.js?v=fb556155 +2ms
  vite:import-analysis 0.85ms [1 imports rewritten] node_modules/.vite/deps/react_jsx-dev-runtime.js?v=fb556155 +32ms
  vite:transform 1.24ms /node_modules/.vite/deps/react_jsx-dev-runtime.js?v=fb556155 +32ms
  vite:time 143.00ms /src/main.jsx +34ms
  vite:import-analysis 0.04ms [no imports] node_modules/vite/dist/client/env.mjs +1ms
  vite:transform 34.39ms /node_modules/vite/dist/client/env.mjs +1ms
  vite:time 38.78ms /node_modules/vite/dist/client/env.mjs +1ms
  vite:load 42.83ms [plugin] /node_modules/.vite/deps/react-dom_client.js?v=fb556155 +4ms
  vite:import-analysis 7.42ms [1 imports rewritten] node_modules/.vite/deps/react-dom_client.js?v=fb556155 +14ms
  vite:transform 12.65ms /node_modules/.vite/deps/react-dom_client.js?v=fb556155 +14ms
  vite:import-analysis /node_modules/.vite/deps/react.js?v=fb556155 needs interop +4ms
  vite:resolve 0.22ms ./assets/react.svg -> /Users/dario/opensource/vite-project/src/assets/react.svg +51ms
  vite:resolve 0.16ms /src/assets/react.svg -> /Users/dario/opensource/vite-project/src/assets/react.svg +0ms
  vite:resolve 0.16ms ./App.css -> /Users/dario/opensource/vite-project/src/App.css +1ms
  vite:resolve 0.15ms /src/App.css -> /Users/dario/opensource/vite-project/src/App.css +0ms
  vite:resolve 0.16ms ./Test.js -> /Users/dario/opensource/vite-project/src/Test.js +0ms
  vite:resolve 0.13ms /src/Test.js -> /Users/dario/opensource/vite-project/src/Test.js +0ms
  vite:hmr [self-accepts] src/App.jsx +0ms
  vite:import-analysis 3.75ms [6 imports rewritten] src/App.jsx +3ms
  vite:transform 54.15ms /src/App.jsx +8ms
  vite:cache [memory] /@react-refresh +0ms
  vite:cache [memory] /node_modules/.vite/deps/react.js?v=fb556155 +1ms
  vite:cache [memory] react/jsx-dev-runtime +0ms
  vite:load 0.29ms [plugin] /src/assets/react.svg +23ms
  vite:import-analysis 0.01ms [no imports] src/assets/react.svg +3ms
  vite:transform 0.15ms /src/assets/react.svg +2ms
  vite:cache [304] react/jsx-dev-runtime +0ms
  vite:time 0.26ms /@id/__x00__react/jsx-dev-runtime +26ms
  vite:load 58.73ms [plugin] /node_modules/.vite/deps/chunk-MQMBJ7LP.js?v=fb556155 +3ms
  vite:import-analysis 0.56ms [no imports] node_modules/.vite/deps/chunk-MQMBJ7LP.js?v=fb556155 +4ms
  vite:transform 1.20ms /node_modules/.vite/deps/chunk-MQMBJ7LP.js?v=fb556155 +4ms
  vite:load 7.56ms [fs] /src/App.css +4ms
  vite:load 8.24ms [fs] /src/Test.js +1ms
  vite:import-analysis 0.01ms [no imports] src/Test.js +4ms
  vite:transform 0.24ms /src/Test.js +4ms
  vite:time 7.99ms /src/App.jsx +7ms
  vite:hmr [self-accepts] src/index.css +15ms
  vite:import-analysis 0.25ms [0 imports rewritten] src/index.css +4ms
  vite:transform 39.91ms /src/index.css +4ms
  vite:time 10.59ms /src/index.css +3ms
  vite:cache [304] /src/assets/react.svg +12ms
  vite:time 2.16ms /src/assets/react.svg?import +2ms
  vite:cache [304] /src/Test.js +2ms
  vite:time 0.35ms /src/Test.js +2ms
  vite:hmr [self-accepts] src/App.css +7ms
  vite:import-analysis 0.18ms [0 imports rewritten] src/App.css +6ms
  vite:transform 10.35ms /src/App.css +6ms
  vite:time 3.19ms /src/App.css +2ms
  vite:time 0.37ms /vite.svg +15ms
  vite:time 0.48ms /src/assets/react.svg +1ms
  vite:time 0.19ms /vite.svg +28ms
  vite:deps ✨ static imports crawl ended +4s

comment out test import in App

  vite:hmr [file change] src/App.jsx +32s
9:03:24 PM [vite] hmr update /src/App.jsx
  vite:load 0.36ms [fs] /src/App.jsx +32s
  vite:import-analysis /node_modules/.vite/deps/react.js?v=fb556155 needs interop +32s
  vite:hmr [self-accepts] src/App.jsx +48ms
  vite:hmr [dispose] /Users/dario/opensource/vite-project/src/Test.js +1ms
  vite:import-analysis 3.77ms [5 imports rewritten] src/App.jsx +3ms
  vite:transform 31.62ms /src/App.jsx +32s
  vite:cache [memory] /@react-refresh +32s
  vite:cache [memory] /node_modules/.vite/deps/react.js?v=fb556155 +1ms
  vite:cache [memory] /src/assets/react.svg +0ms
  vite:cache [memory] /src/App.css +0ms
  vite:cache [memory] react/jsx-dev-runtime +0ms
  vite:time 35.39ms /src/App.jsx +32s


rename Test.js to Test2.js

9:03:48 PM [vite] page reload src/Test.js
  vite:html-fallback Rewriting GET / to /index.html +56s
  vite:time 2.49ms /index.html +24s
  vite:cache [304] /@vite/client +56s
  vite:time 0.66ms /@vite/client +25ms
  vite:load 0.47ms [fs] /src/main.jsx +24s
  vite:import-analysis /node_modules/.vite/deps/react.js?v=fb556155 needs interop +24s
  vite:import-analysis /node_modules/.vite/deps/react-dom_client.js?v=fb556155 needs interop +0ms
  vite:import-analysis 2.50ms [5 imports rewritten] src/main.jsx +2ms
  vite:transform 12.36ms /src/main.jsx +24s
  vite:cache [memory] /node_modules/.vite/deps/react.js?v=fb556155 +24s
  vite:cache [memory] /node_modules/.vite/deps/react-dom_client.js?v=fb556155 +0ms
  vite:cache [memory] /src/App.jsx +0ms
  vite:cache [memory] /src/index.css +0ms
  vite:cache [memory] react/jsx-dev-runtime +0ms
  vite:time 16.69ms /src/main.jsx +17ms
  vite:cache [304] /@react-refresh +22ms
  vite:time 0.28ms /@react-refresh +5ms
  vite:cache [304] /node_modules/vite/dist/client/env.mjs +2ms
  vite:time 0.53ms /node_modules/vite/dist/client/env.mjs +2ms
  vite:cache [304] /src/App.jsx +3ms
  vite:time 0.58ms /src/App.jsx +3ms
  vite:cache [304] /src/index.css +1ms
  vite:time 0.37ms /src/index.css +1ms
  vite:cache [304] react/jsx-dev-runtime +0ms
  vite:time 0.18ms /@id/__x00__react/jsx-dev-runtime +0ms
  vite:cache [304] /src/assets/react.svg +5ms
  vite:time 0.46ms /src/assets/react.svg?import +5ms
  vite:cache [304] /src/App.css +1ms
  vite:time 0.38ms /src/App.css +1ms
  vite:time 0.50ms /src/assets/react.svg +17ms
  vite:time 0.13ms /vite.svg +1ms
  vite:time 0.14ms /vite.svg +4ms

Validations

@patak-dev
Copy link
Member

@dariocravero is this something you can reproduce without React? Let us know, if it is React only we'll move the issue to the new vite-plugin-react repository

@bluwy
Copy link
Member

bluwy commented Nov 7, 2023

This should be fixed in #14315

@bluwy bluwy closed this as completed Nov 7, 2023
@github-actions github-actions bot locked and limited conversation to collaborators Nov 22, 2023
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Projects
None yet
Development

No branches or pull requests

3 participants