Repository navigation
fix(chunk-import-map): keep import map keys unique when chunks share inlined modules - #11226
Closed
mattlewis92 wants to merge 1 commit into
Closed
mattlewis92 wants to merge 1 commit into
mattlewis92 wants to merge 1 commit into
Conversation
mattlewis92
requested review from
IWANABETHATGUY,
hyfdev and
shulaoda
as code owners
October 15, 2026 22:30
…inlined modules A common chunk without a facade module is keyed by its name the first time the name is seen and by its smallest module id after that. With `experimentalInlineCommonChunks`, an inlined record is copied into every carrier chunk, so several same-named carriers can share their smallest module id and get one key. `importmap.json` then holds a single entry for them, and the other carriers' importers resolve to the wrong chunk. When a key is already taken, derive it from the chunk name and all of its module ids, then add a counter until it is unique. Keys that did not collide before are unchanged.
mattlewis92
force-pushed
the
fix/chunk-import-map-unique-keys
branch
from
October 15, 2026 22:33
3bb24f8 to
1ee2567
Compare
Merging this PR will not alter performance
|
Member
|
Hi. Thanks for your efforts! This is a known issue and I've been looking into it for a week. I came up with #11230 which I think a more proper fix direction. |
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
chunkImportMapgives each hashed chunk a stable key. A common chunk without a facade module is keyed by its name the first time that name is seen, and by its smallest module id after that. The fallback assumes no two chunks contain the same module.experimentalInlineCommonChunksbreaks that assumption: an inlined record is copied into every carrier chunk. When three or more same-named carriers (e.g. severallib/index.jschunks) carry the same record and it sorts first in each of them, every carrier after the first gets the same key.importmap.jsonthen has one entry for that key, the other carriers have no entry at all, and their importers load the wrong chunk. At runtime this shows up as an importer reading the wrong values, or asThe requested module './x.js' does not provide an export named '…'.Fix
Track the stable file names already handed out. When a chunk's key is taken, hash the chunk name plus all of its module ids (sorted), and if that is taken too, keep hashing in a counter until the key is unique.
args.chunksis an index map in chunk order, the same order the existing first-seen-name logic already depends on, so the result is deterministic across builds.The plugin only sees
module_ids, which include inlined copies, so it can't key on a chunk's own modules. Hashing every module id is the next most specific input, and the counter covers the theoretical case of two chunks with the same name and the same module set.Test
function/inline_common_chunks/chunk_import_map_unique_keys: three entries share three common chunks namedlib, each carrying an inlined copy ofcommon/shared.js, which sorts before everypackages/*/lib/index.js._test.mjsasserts that every hashed chunk has its ownimportmap.jsonentry, then runs the entries with a resolve hook that applies the import map the way a browser would. The fixture hassnapshot: false, because the fallback keys hash absolute module ids, so they differ between checkouts.On
mainthe fixture fails, because two of thelibchunks share one key:Without that assertion, the runtime check also fails on
main: thebazimporters resolve to thebarchunk ('a shared:foo shared:bar'instead of'a shared:foo shared:baz'). With the fix, both pass, and the two keys that didn't collide are the same as onmain.cargo test -p rolldown --test integrationshows the same results before and after, apart from the new fixture.