fix: include importer in SSR externalization cache key#22080
Open
deyaaeldeen wants to merge 1 commit intovitejs:mainfrom
Open
fix: include importer in SSR externalization cache key#22080deyaaeldeen wants to merge 1 commit intovitejs:mainfrom
deyaaeldeen wants to merge 1 commit intovitejs:mainfrom
Conversation
The `processedIds` cache in `createIsExternal` keys entries by bare
specifier alone, ignoring the importer. In monorepos where different
importers resolve the same specifier to different physical packages
(e.g., `@azure/core-lro@2.7.2` vs `@azure/core-lro@3.x`), the first
resolution's externalization decision is incorrectly reused for all
subsequent importers.
Fix: use a composite cache key of `${id}\0${importer}` so each
(specifier, importer) pair is evaluated independently.
Fixes vitejs#22078
Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
84495f2 to
e8d28ff
Compare
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Problem
createIsExternalcaches externalization decisions in aprocessedIdsmap keyed solely by the bare specifier string, ignoring the importer. In monorepos where different importers resolve the same bare specifier to different physical packages (e.g.,@azure/core-lro@2.7.2vs@azure/core-lro@3.xin a pnpm workspace), the first resolution's externalization decision is incorrectly served to all subsequent importers.Fix
Use a composite cache key
${id}\0${importer}so each (specifier, importer) pair is evaluated independently. Builtins and same-importer lookups still benefit from the cache. The performance impact is negligible sincetryNodeResolveinsideisConfiguredAsExternalalready usespackageCache.Context
Discovered via vitest#10028 in the azure-sdk-for-js monorepo, where the cache causes
@azure/core-lro@2.7.2's externalization result to be applied to@azure/core-lro@3.x, leading to unresolved bare specifiers reaching the module runner and a runtime crash:Fixes #22078