Skip to content

Commit 575bcf6

Browse files
authored
fix: do not append version query param when scanning for dependencies (#11961)
1 parent a873af5 commit 575bcf6

File tree

10 files changed

+63
-1
lines changed

10 files changed

+63
-1
lines changed

packages/vite/src/node/plugins/resolve.ts

+1
Original file line numberDiff line numberDiff line change
@@ -182,6 +182,7 @@ export function resolvePlugin(resolveOptions: InternalResolveOptions): Plugin {
182182
const ensureVersionQuery = (resolved: string): string => {
183183
if (
184184
!options.isBuild &&
185+
!options.scan &&
185186
depsOptimizer &&
186187
!(
187188
resolved === normalizedClientEntry ||

playground/optimize-deps/__tests__/optimize-deps.spec.ts

+6
Original file line numberDiff line numberDiff line change
@@ -143,6 +143,12 @@ test('import aliased package with colon', async () => {
143143
expect(await page.textContent('.url')).toBe('vitejs.dev')
144144
})
145145

146+
test('import aliased package using absolute path', async () => {
147+
expect(await page.textContent('.alias-using-absolute-path')).toBe(
148+
'From dep-alias-using-absolute-path',
149+
)
150+
})
151+
146152
test('variable names are reused in different scripts', async () => {
147153
expect(await page.textContent('.reused-variable-names')).toBe('reused')
148154
})
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
// Importing a shared dependency used by other modules,
2+
// so dependency optimizer creates a common chunk.
3+
// This is used to setup a test scenario, where dep scanner
4+
// could not determine all of the used dependencies on first
5+
// pass, e.g., a dependency that is aliased using an absolute
6+
// path, in which case it used to trigger unnecessary "full
7+
// reloads" invalidating all modules in a module graph.
8+
const cloneDeep = require('lodash/cloneDeep')
9+
10+
// no-op, using imported module for sake of completeness
11+
module.exports = cloneDeep({
12+
message: 'From dep-alias-using-absolute-path',
13+
}).message
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
{
2+
"name": "@vitejs/test-dep-alias-using-absolute-path",
3+
"private": true,
4+
"version": "1.0.0",
5+
"main": "index.js",
6+
"dependencies": {
7+
"lodash": "^4.17.21"
8+
}
9+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
// This is used to setup a test scenario, where dep scanner
2+
// could not determine all of the used dependencies on first
3+
// pass, e.g., a dependency that is aliased using an absolute
4+
// path, in which case it used to trigger unnecessary "full
5+
// reloads" invalidating all modules in a module graph.
6+
export { default } from '@vitejs/test-dep-alias-using-absolute-path'

playground/optimize-deps/index.html

+7
Original file line numberDiff line numberDiff line change
@@ -83,6 +83,9 @@ <h2>Nested include</h2>
8383
<h2>Alias with colon</h2>
8484
<div>URL: <span class="url"></span></div>
8585

86+
<h2>Alias using absolute path</h2>
87+
<div class="alias-using-absolute-path"></div>
88+
8689
<h2>Reused variable names</h2>
8790
<div>This should show reused: <span class="reused-variable-names"></span></div>
8891

@@ -153,6 +156,10 @@ <h2>Non Optimized Module isn't duplicated</h2>
153156
import { parse } from 'node:url'
154157
text('.url', parse('https://vitejs.dev').hostname)
155158

159+
import('./dynamic-use-dep-alias-using-absolute-path.js').then((mod) =>
160+
text('.alias-using-absolute-path', mod.default),
161+
)
162+
156163
import './index.astro'
157164

158165
// All these imports should end up resolved to the same URL (same ?v= injected on them)

playground/optimize-deps/package.json

+1
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,7 @@
1111
"dependencies": {
1212
"axios": "^0.27.2",
1313
"clipboard": "^2.0.11",
14+
"@vitejs/test-dep-alias-using-absolute-path": "file:./dep-alias-using-absolute-path",
1415
"@vitejs/test-dep-cjs-browser-field-bare": "file:./dep-cjs-browser-field-bare",
1516
"@vitejs/test-dep-cjs-compiled-from-cjs": "file:./dep-cjs-compiled-from-cjs",
1617
"@vitejs/test-dep-cjs-compiled-from-esm": "file:./dep-cjs-compiled-from-esm",

playground/optimize-deps/vite.config.js

+4-1
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,9 @@ module.exports = {
1111
dedupe: ['react'],
1212
alias: {
1313
'node:url': 'url',
14+
'@vitejs/test-dep-alias-using-absolute-path': require.resolve(
15+
'@vitejs/test-dep-alias-using-absolute-path',
16+
),
1417
},
1518
},
1619
optimizeDeps: {
@@ -38,7 +41,7 @@ module.exports = {
3841
},
3942
],
4043
},
41-
entries: ['entry.js'],
44+
entries: ['index.html', 'unused-split-entry.js'],
4245
},
4346

4447
build: {

pnpm-lock.yaml

+16
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

0 commit comments

Comments
 (0)