-
-
Notifications
You must be signed in to change notification settings - Fork 7.6k
Closed
Labels
p3-significantHigh priority enhancement (priority)High priority enhancement (priority)
Description
Describe the bug
Vite allows plugins to insert javascript modules into index.html. If the number of scripts inserted into index.html varies between the Vite runs, Vite will incorrectly respond with "304 Not Modified" when browser requests a script that changed between the Vite runs.
Reproduction
https://github.com/maxpatiiuk/vite-etag-bug/
Steps to reproduce
-
Clone this repository
git clone https://github.com/maxpatiiuk/vite-etag-bug/
-
Install
vitenpm install
-
Start the dev server
npx vite
-
Open the browser console, and see "last script" printed once (EXPECTED). Important: make sure caching is NOT disabled in your browser dev tools
-
Stop the dev server, and start it again with the following command:
MODE=include_first_script npx vite
-
EXPECTED to see "first script" and "last script" in the console. INSTEAD, saw "last script" printed twice.
- Disabling browser cache and reloading the page shows "first script" and "last script" as expected.
System Info
System:
OS: macOS 14.6.1
CPU: (10) arm64 Apple M1 Pro
Memory: 398.33 MB / 32.00 GB
Shell: 5.9 - /bin/zsh
Binaries:
Node: 20.16.0 - ~/.nvm/versions/node/v20.16.0/bin/node
Yarn: 1.22.19 - ~/.nvm/versions/node/v20.16.0/bin/yarn
npm: 10.8.1 - ~/.nvm/versions/node/v20.16.0/bin/npm
pnpm: 8.9.0 - ~/.nvm/versions/node/v20.16.0/bin/pnpm
Browsers:
Chrome: 128.0.6613.113
Safari: 17.6
npmPackages:
vite: ^5.2.0 => 5.4.2Used Package Manager
npm
Logs
Debug log from 1st run
vite:config bundled config file loaded in 38.56ms +0ms
vite:config using resolved config: {
vite:config server: {
vite:config preTransformRequests: true,
vite:config open: true,
vite:config port: 9999,
vite:config sourcemapIgnoreList: [Function: isInNodeModules$1],
vite:config middlewareMode: false,
vite:config fs: {
vite:config strict: true,
vite:config allow: [Array],
vite:config deny: [Array],
vite:config cachedChecks: undefined
vite:config }
vite:config },
vite:config plugins: [
vite:config 'vite:optimized-deps',
vite:config 'vite:watch-package-data',
vite:config 'vite:pre-alias',
vite:config 'alias',
vite:config 'vite:modulepreload-polyfill',
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 'etag-bug-reproduction',
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:css-analysis',
vite:config 'vite:import-analysis'
vite:config ],
vite:config optimizeDeps: {
vite:config holdUntilCrawlEnd: true,
vite:config force: undefined,
vite:config esbuildOptions: { preserveSymlinks: false }
vite:config },
vite:config configFile: '/Users/mak13180/site/esri/vite-etag-wrong-url/vite.config.js',
vite:config configFileDependencies: [ '/Users/mak13180/site/esri/vite-etag-wrong-url/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: { host: undefined }
vite:config },
vite:config root: '/Users/mak13180/site/esri/vite-etag-wrong-url',
vite:config base: '/',
vite:config decodedBase: '/',
vite:config rawBase: '/',
vite:config resolve: {
vite:config mainFields: [ 'browser', 'module', 'jsnext:main', 'jsnext' ],
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: [],
vite:config preserveSymlinks: false,
vite:config alias: [ [Object], [Object] ]
vite:config },
vite:config publicDir: '/Users/mak13180/site/esri/vite-etag-wrong-url/public',
vite:config cacheDir: '/Users/mak13180/site/esri/vite-etag-wrong-url/node_modules/.vite',
vite:config command: 'serve',
vite:config mode: 'development',
vite:config ssr: {
vite:config target: 'node',
vite:config optimizeDeps: { noDiscovery: true, esbuildOptions: [Object] }
vite:config },
vite:config isWorker: false,
vite:config mainConfig: null,
vite:config bundleChain: [],
vite:config isProduction: false,
vite:config css: { lightningcss: undefined },
vite:config esbuild: { jsxDev: true },
vite:config build: {
vite:config target: [ 'es2020', 'edge88', 'firefox78', 'chrome87', 'safari14' ],
vite:config cssTarget: [ 'es2020', 'edge88', 'firefox78', 'chrome87', 'safari14' ],
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 ssrEmitAssets: 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 cssMinify: 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: true,
vite:config proxy: undefined,
vite:config cors: undefined,
vite:config headers: undefined
vite:config },
vite:config envDir: '/Users/mak13180/site/esri/vite-etag-wrong-url',
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(1) {
vite:config 'fnpd_/Users/mak13180/site/esri/vite-etag-wrong-url' => {
vite:config dir: '/Users/mak13180/site/esri/vite-etag-wrong-url',
vite:config data: [Object],
vite:config hasSideEffects: [Function: hasSideEffects],
vite:config webResolvedImports: {},
vite:config nodeResolvedImports: {},
vite:config setResolvedCache: [Function: setResolvedCache],
vite:config getResolvedCache: [Function: getResolvedCache]
vite:config },
vite:config set: [Function (anonymous)]
vite:config },
vite:config createResolver: [Function: createResolver],
vite:config worker: { format: 'iife', plugins: '() => plugins', rollupOptions: {} },
vite:config appType: 'spa',
vite:config experimental: { importGlobRestoreExtension: false, hmrPartialAccept: false },
vite:config getSortedPlugins: [Function: getSortedPlugins],
vite:config getSortedPluginHooks: [Function: getSortedPluginHooks]
vite:config } +4ms
vite:deps Hash is consistent. Skipping. Use --force to override. +0ms
VITE v5.4.2 ready in 125 ms
➜ Local: http://localhost:9999/
➜ Network: use --host to expose
➜ press h + enter to show help
vite:html-fallback Rewriting GET / to /index.html +0ms
vite:time 11.54ms /index.html +0ms
vite:resolve 2.36ms /index.html?html-proxy&index=0.js -> /Users/mak13180/site/esri/vite-etag-wrong-url/index.html?html-proxy&index=0.js +0ms
vite:resolve 2.16ms /main.js -> /Users/mak13180/site/esri/vite-etag-wrong-url/main.js +0ms
vite:load 0.55ms [plugin] /index.html?html-proxy&index=0.js +0ms
vite:import-analysis 0.22ms [no imports] index.html?html-proxy&index=0.js +0ms
vite:transform 1.80ms /index.html?html-proxy&index=0.js +0ms
vite:load 3.65ms [fs] /main.js +3ms
vite:import-analysis 0.06ms [no imports] main.js +2ms
vite:transform 0.32ms /main.js +2ms
vite:html-fallback Rewriting GET / to /index.html +392ms
vite:cache [memory] /index.html?html-proxy&index=0.js +0ms
vite:cache [memory] /main.js +0ms
vite:time 2.46ms /index.html +382ms
vite:cache [304] /index.html?html-proxy&index=0.js +0ms
vite:time 0.37ms /index.html?html-proxy&index=0.js +42ms
vite:resolve 0.43ms /@vite/client -> /Users/mak13180/site/esri/vite-etag-wrong-url/node_modules/vite/dist/client/client.mjs +433ms
vite:cache [304] /main.js +33ms
vite:time 0.10ms /main.js +32ms
vite:load 103.51ms [fs] /@vite/client +538ms
vite:resolve 0.18ms @vite/env -> /Users/mak13180/site/esri/vite-etag-wrong-url/node_modules/vite/dist/client/env.mjs +115ms
vite:import-analysis 2.64ms [1 imports rewritten] node_modules/vite/dist/client/client.mjs +544ms
vite:transform 3.04ms /@vite/client +544ms
vite:time 116.47ms /@vite/client +94ms
vite:load 3.12ms [fs] /node_modules/vite/dist/client/env.mjs +10ms
vite:import-analysis 0.05ms [no imports] node_modules/vite/dist/client/env.mjs +4ms
vite:transform 0.25ms /node_modules/vite/dist/client/env.mjs +4ms
vite:cache [304] /node_modules/vite/dist/client/env.mjs +99ms
vite:time 0.07ms /node_modules/vite/dist/client/env.mjs +5msDebug log from 2nd run
vite:config bundled config file loaded in 18.76ms +0ms
vite:config using resolved config: {
vite:config server: {
vite:config preTransformRequests: true,
vite:config open: true,
vite:config port: 9999,
vite:config sourcemapIgnoreList: [Function: isInNodeModules$1],
vite:config middlewareMode: false,
vite:config fs: {
vite:config strict: true,
vite:config allow: [Array],
vite:config deny: [Array],
vite:config cachedChecks: undefined
vite:config }
vite:config },
vite:config plugins: [
vite:config 'vite:optimized-deps',
vite:config 'vite:watch-package-data',
vite:config 'vite:pre-alias',
vite:config 'alias',
vite:config 'vite:modulepreload-polyfill',
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 'etag-bug-reproduction',
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:css-analysis',
vite:config 'vite:import-analysis'
vite:config ],
vite:config optimizeDeps: {
vite:config holdUntilCrawlEnd: true,
vite:config force: undefined,
vite:config esbuildOptions: { preserveSymlinks: false }
vite:config },
vite:config configFile: '/Users/mak13180/site/esri/vite-etag-wrong-url/vite.config.js',
vite:config configFileDependencies: [ '/Users/mak13180/site/esri/vite-etag-wrong-url/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: { host: undefined }
vite:config },
vite:config root: '/Users/mak13180/site/esri/vite-etag-wrong-url',
vite:config base: '/',
vite:config decodedBase: '/',
vite:config rawBase: '/',
vite:config resolve: {
vite:config mainFields: [ 'browser', 'module', 'jsnext:main', 'jsnext' ],
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: [],
vite:config preserveSymlinks: false,
vite:config alias: [ [Object], [Object] ]
vite:config },
vite:config publicDir: '/Users/mak13180/site/esri/vite-etag-wrong-url/public',
vite:config cacheDir: '/Users/mak13180/site/esri/vite-etag-wrong-url/node_modules/.vite',
vite:config command: 'serve',
vite:config mode: 'development',
vite:config ssr: {
vite:config target: 'node',
vite:config optimizeDeps: { noDiscovery: true, esbuildOptions: [Object] }
vite:config },
vite:config isWorker: false,
vite:config mainConfig: null,
vite:config bundleChain: [],
vite:config isProduction: false,
vite:config css: { lightningcss: undefined },
vite:config esbuild: { jsxDev: true },
vite:config build: {
vite:config target: [ 'es2020', 'edge88', 'firefox78', 'chrome87', 'safari14' ],
vite:config cssTarget: [ 'es2020', 'edge88', 'firefox78', 'chrome87', 'safari14' ],
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 ssrEmitAssets: 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 cssMinify: 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: true,
vite:config proxy: undefined,
vite:config cors: undefined,
vite:config headers: undefined
vite:config },
vite:config envDir: '/Users/mak13180/site/esri/vite-etag-wrong-url',
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(1) {
vite:config 'fnpd_/Users/mak13180/site/esri/vite-etag-wrong-url' => {
vite:config dir: '/Users/mak13180/site/esri/vite-etag-wrong-url',
vite:config data: [Object],
vite:config hasSideEffects: [Function: hasSideEffects],
vite:config webResolvedImports: {},
vite:config nodeResolvedImports: {},
vite:config setResolvedCache: [Function: setResolvedCache],
vite:config getResolvedCache: [Function: getResolvedCache]
vite:config },
vite:config set: [Function (anonymous)]
vite:config },
vite:config createResolver: [Function: createResolver],
vite:config worker: { format: 'iife', plugins: '() => plugins', rollupOptions: {} },
vite:config appType: 'spa',
vite:config experimental: { importGlobRestoreExtension: false, hmrPartialAccept: false },
vite:config getSortedPlugins: [Function: getSortedPlugins],
vite:config getSortedPluginHooks: [Function: getSortedPluginHooks]
vite:config } +4ms
vite:deps Hash is consistent. Skipping. Use --force to override. +0ms
VITE v5.4.2 ready in 101 ms
➜ Local: http://localhost:9999/
➜ Network: use --host to expose
➜ press h + enter to show help
vite:html-fallback Rewriting GET / to /index.html +0ms
vite:time 10.96ms /index.html +0ms
vite:resolve 2.39ms /index.html?html-proxy&index=0.js -> /Users/mak13180/site/esri/vite-etag-wrong-url/index.html?html-proxy&index=0.js +0ms
vite:resolve 2.25ms /index.html?html-proxy&index=1.js -> /Users/mak13180/site/esri/vite-etag-wrong-url/index.html?html-proxy&index=1.js +0ms
vite:resolve 2.12ms /main.js -> /Users/mak13180/site/esri/vite-etag-wrong-url/main.js +0ms
vite:load 0.35ms [plugin] /index.html?html-proxy&index=0.js +0ms
vite:load 0.37ms [plugin] /index.html?html-proxy&index=1.js +0ms
vite:import-analysis 0.29ms [no imports] index.html?html-proxy&index=0.js +0ms
vite:import-analysis 0.31ms [no imports] index.html?html-proxy&index=1.js +0ms
vite:transform 1.91ms /index.html?html-proxy&index=0.js +0ms
vite:transform 1.90ms /index.html?html-proxy&index=1.js +0ms
vite:load 3.33ms [fs] /main.js +3ms
vite:import-analysis 0.01ms [no imports] main.js +2ms
vite:transform 0.07ms /main.js +2ms
vite:time 0.10ms / +182ms
vite:html-fallback Rewriting GET / to /index.html +199ms
vite:cache [memory] /index.html?html-proxy&index=0.js +0ms
vite:cache [memory] /index.html?html-proxy&index=1.js +0ms
vite:cache [memory] /main.js +0ms
vite:time 2.29ms /index.html +8ms
vite:resolve 0.25ms /@vite/client -> /Users/mak13180/site/esri/vite-etag-wrong-url/node_modules/vite/dist/client/client.mjs +200ms
vite:cache [304] /index.html?html-proxy&index=0.js +0ms
vite:time 0.05ms /index.html?html-proxy&index=0.js +12ms
vite:load 1.26ms [fs] /@vite/client +198ms
vite:resolve 0.26ms @vite/env -> /Users/mak13180/site/esri/vite-etag-wrong-url/node_modules/vite/dist/client/env.mjs +9ms
vite:import-analysis 4.60ms [1 imports rewritten] node_modules/vite/dist/client/client.mjs +205ms
vite:transform 5.34ms /@vite/client +205ms
vite:time 10.04ms /@vite/client +9ms
vite:cache [304] /index.html?html-proxy&index=1.js +10ms
vite:time 0.05ms /index.html?html-proxy&index=1.js +1ms
vite:cache [304] /main.js +1ms
vite:time 0.07ms /main.js +1ms
vite:load 2.13ms [fs] /node_modules/vite/dist/client/env.mjs +10ms
vite:import-analysis 0.05ms [no imports] node_modules/vite/dist/client/env.mjs +2ms
vite:transform 0.20ms /node_modules/vite/dist/client/env.mjs +2ms
vite:html-fallback Rewriting GET / to /index.html +79ms
vite:cache [memory] /index.html?html-proxy&index=0.js +78ms
vite:cache [memory] /index.html?html-proxy&index=1.js +0ms
vite:cache [memory] /main.js +0ms
vite:time 1.54ms /index.html +55ms
vite:cache [304] /@vite/client +81ms
vite:time 0.11ms /@vite/client +26ms
vite:cache [304] /main.js +4ms
vite:time 0.12ms /main.js +4ms
vite:cache [304] /index.html?html-proxy&index=0.js +0ms
vite:time 0.04ms /index.html?html-proxy&index=0.js +0ms
vite:cache [304] /index.html?html-proxy&index=1.js +1ms
vite:time 0.04ms /index.html?html-proxy&index=1.js +1ms
vite:cache [304] /node_modules/vite/dist/client/env.mjs +83ms
vite:time 0.10ms /node_modules/vite/dist/client/env.mjs +83ms```
</details>
### Validations
- [X] Follow our [Code of Conduct](https://github.com/vitejs/vite/blob/main/CODE_OF_CONDUCT.md)
- [X] Read the [Contributing Guidelines](https://github.com/vitejs/vite/blob/main/CONTRIBUTING.md).
- [X] Read the [docs](https://vitejs.dev/guide).
- [X] Check that there isn't [already an issue](https://github.com/vitejs/vite/issues) that reports the same bug to avoid creating a duplicate.
- [X] Make sure this is a Vite issue and not a framework-specific issue. For example, if it's a Vue SFC related bug, it should likely be reported to [vuejs/core](https://github.com/vuejs/core) instead.
- [X] Check that this is a concrete bug. For Q&A open a [GitHub Discussion](https://github.com/vitejs/vite/discussions) or join our [Discord Chat Server](https://chat.vitejs.dev/).
- [X] The provided reproduction is a [minimal reproducible example](https://stackoverflow.com/help/minimal-reproducible-example) of the bug.Metadata
Metadata
Assignees
Labels
p3-significantHigh priority enhancement (priority)High priority enhancement (priority)