Skip to content

fix(chunk-import-map): hash stable module ids so keys don't depend on the build folder - #11277

Merged
hyfdev merged 4 commits into
rolldown:mainfrom
mandyheg:fix/chunk-import-map-stable-module-id
Oct 26, 2026
Merged

hyfdev merged 4 commits into
rolldown:mainfrom
mandyheg:fix/chunk-import-map-stable-module-id

Conversation

@mandyheg

@mandyheg mandyheg commented Oct 23, 2026 •

Copy link
Copy Markdown
Contributor

Building identical sources from different directories changes chunk import-map keys and can change filenames of chunks that reference those keys.

Filesystem module IDs contribute cwd-relative paths to import-map keys; non-path IDs retain their original strings. A path/non-path discriminator keeps those identities distinct for entry chunks and same-named common chunks.

The tests check that moving the build directory preserves import maps and chunk filenames, and that filesystem and non-path modules with matching relative IDs resolve to their own code. Existing aliases change once after upgrading.

Fixes #11279
Related: #9557

@codspeed

codspeed Bot commented Oct 23, 2026 •

Copy link
Copy Markdown

Merging this PR will not alter performance

1 warning

⚠️ 4 benchmarks are dominated by system calls

System calls cannot be simulated consistently and are left out of the measure. The reported value understates the real cost. Switch to the Walltime instrument to measure them.

Learn more about system calls

See affected benchmarks

✅ 7 untouched benchmarks
⏩ 10 skipped benchmarks1


Comparing mandyheg:fix/chunk-import-map-stable-module-id (194d3b6) with main (c50bb60)2

Open in CodSpeed

Footnotes

  1. 10 benchmarks were skipped, so the baseline results were used instead. If they were deleted from the codebase, click here and archive them to remove them from the performance reports. ↩

  2. No successful run was found on main (9b5f62e) during the generation of this report, so c50bb60 was used instead as the comparison base. There might be some changes unrelated to this pull request in this report. ↩

@hyfdev hyfdev self-assigned this Oct 24, 2026
@netlify

netlify Bot commented Oct 24, 2026 •

Copy link
Copy Markdown

✅ Deploy Preview for rolldown-rs ready!

Name Link
🔨 Latest commit 194d3b6
🔍 Latest deploy log https://app.netlify.com/projects/rolldown-rs/deploys/6adec706d809e94d0daa716b
😎 Deploy Preview https://deploy-preview-11277--rolldown-rs.netlify.app
📱 Preview on mobile
Toggle QR Code...

QR Code

Use your smartphone camera to open QR code link.
🤖 Make changes Run an agent on this branch

To edit notification comments on pull requests, go to your Netlify project configuration.

hyfdev commented Oct 24, 2026

Copy link
Copy Markdown
Member

Thanks for the fix! I pushed a follow-up in 95ea879:

  • Collision: With cwd: '/project', the file ID /project/lazy.js and a plugin-provided ID lazy.js both become the stable ID lazy.js.
  • Impact: If their chunks have the same name, they get the same import-map key. One mapping overwrites the other, so both imports load the same output file.
  • Fix: Include a path/non-path marker in the hash. Filesystem paths remain relative to cwd; non-path IDs keep their original strings.
  • Tests: Check that entry chunks and same-named common chunks retain distinct keys and execute the correct code.

iAmNathanJ added a commit to iAmNathanJ/rolldown that referenced this pull request Oct 24, 2026
…sparent for hashing

`chunkImportMap` aliased every hashed chunk, which makes the import map as
large as the output. Large apps only need a few widely shared chunks aliased
to stop content hashes from cascading, and inline the import map in HTML,
so they need to choose.

`include: (chunk: PreRenderedChunk) => boolean` selects the aliased chunks.

Aliasing only some chunks changes what a hash must cover. Before, no
placeholder survived in any chunk's code, so each hash was a function of
that chunk's bytes. Now an importer still references unaliased chunks
through placeholders, and an aliased chunk can sit between the importer
and unaliased chunks behind it. Tools that write file names into chunks
after hashing — Vite's `__vite__mapDeps` lists every chunk reached through
the static imports of a dynamic import target — embed those chunks' final
names in the importer. A hash that stopped at the alias would let two
builds emit different bytes under one file name.

So an aliased chunk is transparent for hashing: `finalize_assets` reads the
dependency graph from the original placeholders, writes the alias hashes
into contents (same width, so sourcemaps hold) before the standalone
content hash, and replaces every edge to an aliased chunk with edges to
the hashed chunks its *static* imports reach, through any chain of
aliased chunks. Static imports are the load-time dependency surface a
chunk exposes (the set hoisting and module-preload tooling emit); its
dynamic imports are resolved from its own content under its own name and
never appear in an importer, so following them would make every importer
of a shared chunk inherit that chunk's whole lazy closure. The aliased
chunk's own file still gets its content hash. When every hashed chunk is
aliased, no edge survives and hashing behaves as before.

Alias identities hash `(is_path, id)` with filesystem ids stabilized
against `cwd` and other ids verbatim, and key later same-named common
chunks by the smallest module among their original logical members (as
rolldown#11277 does), so aliases are the same wherever the
project is built.

The `builtin:chunk-import-map` plugin no longer rewrites chunk code; it
emits the import map from the aliases `finalize_assets` recorded.
@hyfdev

hyfdev commented Oct 25, 2026

Copy link
Copy Markdown
Member

LGTM. Thank you!

iAmNathanJ added a commit to iAmNathanJ/rolldown that referenced this pull request Oct 25, 2026
…parent for hashing

Adds `include: (chunk) => boolean` to `experimental.chunkImportMap`. Only chunks for which it
returns true get a stable name in the import map; all other chunks keep content-hashed names.
When `include` is unset, every hashed chunk is mapped, as before.

A mapped chunk is transparent for hashing: an importer's hash does not include the mapped
chunk's content, but it does include the hashed chunks reached through the mapped chunk's
static imports, through any chain of mapped chunks. Post-hash tooling (Vite's module preload
lists) writes those names into importers, so their hashes must cover them.

Stable names are derived from (is_path, id relative to cwd) for facade chunks and from the
chunk name for common chunks, as in rolldown#11277, so they do not depend on the build directory.

The chunk import map plugin no longer rewrites code in renderChunk; stable names are
substituted in finalize_assets and the plugin only emits the map.
@hyfdev
hyfdev enabled auto-merge (squash) October 26, 2026 03:20
@hyfdev
hyfdev force-pushed the fix/chunk-import-map-stable-module-id branch from 95ea879 to 194d3b6 Compare October 26, 2026 03:20
@hyfdev
hyfdev merged commit dd6b8e2 into rolldown:main Oct 26, 2026
34 of 35 checks passed
@mandyheg

Copy link
Copy Markdown
Contributor Author

Thanks @hyfdev!

This was referenced Oct 29, 2026
shulaoda added a commit that referenced this pull request Oct 29, 2026
## [1.2.16] - 2026-10-29

### 🚀 Features

- perf-kit: check rendered output against the original build (#11140) by @IWANABETHATGUY
- perf-kit: node/deno server startup mode (#10601) by @IWANABETHATGUY
- perf-kit: browser page-load perf harness for coding agents (#10365) by @IWANABETHATGUY
- devtools: report mode - agent-readable build metrics report (#10364) by @IWANABETHATGUY
- inline-common-chunks: print record factories parenthesized so they compile eagerly (#11282) by @mattlewis92
- fold `'key' in ns` on namespace imports with statically known exports (#11333) by @danielroe
- inline-common-chunks: inline chunks using `import.meta.hot` in dev mode (#11339) by @hyfdev
- support `experimentalInlineCommonChunks` in dev mode (#11335) by @hyfdev
- use `INVALID_TLA_FORMAT` error for Rollup compatibility (#11266) by @sapphi-red

### 🐛 Bug Fixes

- await bundle.close() in loadConfig and clean up every generated config file (#10347) by @Brooooooklyn
- deps: update mimalloc-safe to 0.1.69 (#11376) by @shulaoda
- transform: don't crash when the working directory has been deleted (#11352) by @shulaoda
- import-glob: follow directory symlinks on the wasm binding (#10624) by @hyfdev
- tree-shaking: preserve exported rest bindings from dynamic imports (#11365) by @shuvroroy
- transform: report `tsconfigFilePaths` for a tsconfig resolved through `TsconfigCache` (#11346) by @cainrus
- tsconfig: don't apply tsconfig when resolving imports from virtual modules (#11089) by @rubas
- code-splitting: handle emitted entries the same as `input` entries when placing the runtime (#11353) by @IWANABETHATGUY
- error: make Diagnostic::add_file idempotent (#10610) by @Nic-Polumeyv
- avoid retaining callable builtin callback owners (#10961) by @IWANABETHATGUY
- code-splitting: only host the runtime in a chunk that every consumer's entries load (#11293) by @IWANABETHATGUY
- code-splitting: keep the source order of chunk imports (#11298) by @IWANABETHATGUY
- dev: don't treat a wrapped module's init as a no-op in dev mode (#11334) by @hyfdev
- treat `cwd` as a literal path in relative glob filters (#11291) by @onmax
- deps: update emnapi to 2.0.0-beta.2 and pin `@napi-rs/wasm-runtime` to 1.2.6 (#11292) by @IWANABETHATGUY
- chunk-import-map: hash stable module ids so keys don't depend on the build folder (#11277) by @mandyheg
- respect CPU limits when sizing native runtime workers (#11280) by @Brooooooklyn
- deconflict the namespace of a module without module syntax (#11256) by @IWANABETHATGUY
- code-splitting: rebuild an absorbed dynamic entry's namespace from what its imports read (#11200) by @mattlewis92
- escape line terminators in debug-info comments (#11258) by @IWANABETHATGUY

### 🚜 Refactor

- extract callable builtin hook wrapper (#10964) by @IWANABETHATGUY

### 📚 Documentation

- add an in-depth explanation for inline common chunks (#11239) by @hyfdev

### ⚡ Performance

- incremental cycle check for `avoidRedundantChunkLoads` (#11320) by @IWANABETHATGUY
- avoid copying module code for `renderedLength` and share `chunk.code` across plugins (#11342) by @IWANABETHATGUY
- count UTF-16 lengths with `simd-utf16-len` (#11259) by @IWANABETHATGUY
- don't load consola when importing rolldown (#11257) by @magurotuna

### 🧪 Testing

- dev: cover hot updates that need modules the tab never received (#9647) by @matthewdavis-oai
- dev: add dynamic import rebuild test (#7123) by @sapphi-red
- code-splitting: import file URLs in fresh-process runtime host tests on Windows (#11354) by @shulaoda
- esbuild: mark loader_data_url_base64_invalid_utf8 as an intentional difference (#10790) by @CoderSerio
- watch: fix flaky `watch buildDelay` (#11175) by @Brooooooklyn

### ⚙️ Miscellaneous Tasks

- install `cmake-core` instead of the `cmake` metapackage on FreeBSD (#11361) by @shulaoda
- deps: update oxc to 0.156.0 (#11326) by @Dunqing
- stop the Discord notification when the metric workflow fails (#11357) by @IWANABETHATGUY
- connect to the Void platform before the docs deploy (#11350) by @shulaoda
- deps: update rust crates (#11297) by @renovate[bot]
- deps: update dependency vite-plus to v1.4.0 (#11288) by @renovate[bot]
- deps: update npm packages (#11296) by @renovate[bot]
- deps: update napi (#11287) by @renovate[bot]
- deps: update rollup submodule for tests to v4.65.1 (#11331) by @rolldown-guard[bot]
- deps: update test262 submodule for tests (#11332) by @rolldown-guard[bot]
- deps: update dependency rolldown-plugin-dts to v0.28.8 (#11286) by @renovate[bot]
- deps: bump tokio to 1.53.3 (#11317) by @Brooooooklyn

### ❤️ New Contributors

* @mattlewis92 made their first contribution in [#11282](#11282)
* @shuvroroy made their first contribution in [#11365](#11365)
* @cainrus made their first contribution in [#11346](#11346)
* @matthewdavis-oai made their first contribution in [#9647](#9647)
* @rubas made their first contribution in [#11089](#11089)
* @danielroe made their first contribution in [#11333](#11333)
* @onmax made their first contribution in [#11291](#11291)
* @mandyheg made their first contribution in [#11277](#11277)
* @magurotuna made their first contribution in [#11257](#11257)

Co-authored-by: shulaoda <165626830+shulaoda@users.noreply.github.com>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

[Bug]: chunkImportMap keys change when the project is built from a different path

3 participants