Skip to content

Commit 446fe83

Browse files
authored
fix(optimizer): incorrect incompatible error (#20439)
1 parent 42993bb commit 446fe83

File tree

2 files changed

+28
-28
lines changed

2 files changed

+28
-28
lines changed

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

Lines changed: 25 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -373,32 +373,8 @@ export function importAnalysisPlugin(config: ResolvedConfig): Plugin {
373373
return [resolved.id, resolved.id]
374374
}
375375

376-
const isRelative = url[0] === '.'
377-
const isSelfImport = !isRelative && cleanUrl(url) === cleanUrl(importer)
378-
379376
url = normalizeResolvedIdToUrl(environment, url, resolved)
380377

381-
// make the URL browser-valid
382-
if (environment.config.consumer === 'client') {
383-
// mark non-js/css imports with `?import`
384-
if (isExplicitImportRequired(url)) {
385-
url = injectQuery(url, 'import')
386-
} else if (
387-
(isRelative || isSelfImport) &&
388-
!DEP_VERSION_RE.test(url)
389-
) {
390-
// If the url isn't a request for a pre-bundled common chunk,
391-
// for relative js/css imports, or self-module virtual imports
392-
// (e.g. vue blocks), inherit importer's version query
393-
// do not do this for unknown type imports, otherwise the appended
394-
// query can break 3rd party plugin's extension checks.
395-
const versionMatch = DEP_VERSION_RE.exec(importer)
396-
if (versionMatch) {
397-
url = injectQuery(url, versionMatch[1])
398-
}
399-
}
400-
}
401-
402378
try {
403379
// delay setting `isSelfAccepting` until the file is actually used (#7870)
404380
// We use an internal function to avoid resolving the url again
@@ -423,6 +399,31 @@ export function importAnalysisPlugin(config: ResolvedConfig): Plugin {
423399
throw e
424400
}
425401

402+
// make the URL browser-valid
403+
if (environment.config.consumer === 'client') {
404+
const isRelative = url[0] === '.'
405+
const isSelfImport =
406+
!isRelative && cleanUrl(url) === cleanUrl(importer)
407+
408+
// mark non-js/css imports with `?import`
409+
if (isExplicitImportRequired(url)) {
410+
url = injectQuery(url, 'import')
411+
} else if (
412+
(isRelative || isSelfImport) &&
413+
!DEP_VERSION_RE.test(url)
414+
) {
415+
// If the url isn't a request for a pre-bundled common chunk,
416+
// for relative js/css imports, or self-module virtual imports
417+
// (e.g. vue blocks), inherit importer's version query
418+
// do not do this for unknown type imports, otherwise the appended
419+
// query can break 3rd party plugin's extension checks.
420+
const versionMatch = DEP_VERSION_RE.exec(importer)
421+
if (versionMatch) {
422+
url = injectQuery(url, versionMatch[1])
423+
}
424+
}
425+
}
426+
426427
// prepend base
427428
if (!ssr) url = joinUrlSegments(base, url)
428429

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

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -42,7 +42,7 @@ export function optimizedDepsPlugin(): Plugin {
4242
if (depsOptimizer?.isOptimizedDepFile(id)) {
4343
const metadata = depsOptimizer.metadata
4444
const file = cleanUrl(id)
45-
const versionMatch = DEP_VERSION_RE.exec(file)
45+
const versionMatch = DEP_VERSION_RE.exec(id)
4646
const browserHash = versionMatch
4747
? versionMatch[1].split('=')[1]
4848
: undefined
@@ -77,9 +77,8 @@ export function optimizedDepsPlugin(): Plugin {
7777
try {
7878
return await fsp.readFile(file, 'utf-8')
7979
} catch {
80-
const newMetadata = depsOptimizer.metadata
81-
if (optimizedDepInfoFromFile(newMetadata, file)) {
82-
// Outdated non-entry points (CHUNK), loaded after a rerun
80+
if (browserHash) {
81+
// Outdated optimized files loaded after a rerun
8382
throwOutdatedRequest(id)
8483
}
8584
throwFileNotFoundInOptimizedDep(id)

0 commit comments

Comments
 (0)