Skip to content

fix(build): use stable module ids in chunk import map hash signatures (fix #23975) - #23976

Merged
sapphi-red merged 7 commits into
vitejs:mainfrom
mandyheg:fix/chunk-import-map-preload-hash-stable-ids
Nov 4, 2026
Merged

sapphi-red merged 7 commits into
vitejs:mainfrom
mandyheg:fix/chunk-import-map-preload-hash-stable-ids

Conversation

@mandyheg

@mandyheg mandyheg commented Nov 2, 2026 •

Copy link
Copy Markdown
Contributor

Fixes #23975

The bug:
The import map preload signatures feed absolute file paths into chunk hashes. This means the same code built from two different folders gets different chunk file names.

We build each release of our app in different folders and this prevents us from maximising what the browser caches.

The fix: use paths relative to Rolldown's cwd (rolldownOptions.cwd), falling back to process.cwd(). This is how Rolldown builds its own import map keys. Each id also keeps a file/non-file flag so a file and a virtual module with the same name can't collide (see rolldown/rolldown#11277 (comment)).

AI disclosure: I used Claude, but have reviewed the proposed solution and code myself.

mandyheg and others added 4 commits November 2, 2026 12:57
… folder

Builds the same project from two folders and expects identical output
file names. Fails today because chunk import map preload signatures
include absolute module ids.

Refs vitejs#23975

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
fix vitejs#23975

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
@mandyheg

mandyheg commented Nov 2, 2026

Copy link
Copy Markdown
Contributor Author

CI looks to be failing on unrelated changes to mine as far as I can tell!

@mandyheg
mandyheg marked this pull request as ready for review November 2, 2026 14:03
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>

@agammann agammann left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The new normalization still includes the build folder when Vite is called with root from a fixed process directory and rolldownOptions.cwd is unset. In that ordinary programmatic case, path.relative(process.cwd(), /build-A/src/entry.js) and the same module in /build-B differ, so the facade/module signatures (and chunk hashes) change across releases. The new integration test sets rolldownOptions.cwd: root explicitly, which hides this case. Could the default normalization base use the resolved Vite root, and could the test exercise build({ root }) without setting Rolldown cwd?

@sapphi-red sapphi-red added p3-minor-bug An edge case that only affects very specific usage (priority) feat: build labels Nov 4, 2026
@sapphi-red
sapphi-red merged commit 8069835 into vitejs:main Nov 4, 2026
26 checks passed
@mandyheg

mandyheg commented Nov 4, 2026

Copy link
Copy Markdown
Contributor Author

Thanks for the cleanup and merge @sapphi-red!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

feat: build p3-minor-bug An edge case that only affects very specific usage (priority)

Projects

None yet

Development

Successfully merging this pull request may close these issues.

chunkImportMap: chunk filenames depend on the build folder

3 participants