refactor: use chunk id as the placeholder when calculating content-hash#12271
refactor: use chunk id as the placeholder when calculating content-hash#12271Timeless0911 merged 2 commits intomainfrom
Conversation
✅ Deploy Preview for rspack canceled.
|
There was a problem hiding this comment.
Pull request overview
This PR changes the ESM library plugin to use chunk IDs instead of chunk ukeys as placeholders when calculating content hashes. Previously, the plugin used chunk ukeys (numeric IDs) as placeholders, which could change across compilations and cause issues with hash stability. The new approach uses chunk IDs (strings) which are more stable and resolves problems where outdated ukeys couldn't find their corresponding chunks during replacement.
- Replaced
chunk_ukey.as_u32()calls withChunkGraph::get_chunk_id()calls in render logic - Updated the regex pattern to match chunk ID placeholders instead of numeric ukeys
- Added a
chunk_ids_to_ukeymap to reverse-lookup chunks from their IDs during placeholder replacement
Reviewed changes
Copilot reviewed 2 out of 2 changed files in this pull request and generated 1 comment.
| File | Description |
|---|---|
| crates/rspack_plugin_esm_library/src/render.rs | Updated placeholder generation to use chunk IDs instead of numeric ukeys |
| crates/rspack_plugin_esm_library/src/plugin.rs | Added chunk ID to ukey mapping, updated regex pattern, and modified placeholder replacement logic to use chunk IDs |
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
📦 Binary Size-limit
❌ Size increased by 8.63KB from 47.63MB to 47.64MB (⬆️0.02%) |
CodSpeed Performance ReportMerging #12271 will not alter performanceComparing Summary
|
24ce01a to
9daef11
Compare
Summary
Before I use chunk_ukey as the EsmLibraryPlugin placeholder, place it in output and then calculate hash based on it. And then use the chunk_ukey to find the chunk, and replace the placeholder with the filename of the chunk.
But this have 2 downsides. One is that contenthash is implicitly based on the ukey which is not stable cross compilations. And when ukey changes. the referencing chunk's render result may remains the same, and when replace, can't find the chunk with that outdated ukey
Related links
Checklist