Skip to content

refactor: use chunk id as the placeholder when calculating content-hash#12271

Merged
Timeless0911 merged 2 commits intomainfrom
refactor/using-chunk-id-as-placeholder
Nov 24, 2025
Merged

refactor: use chunk id as the placeholder when calculating content-hash#12271
Timeless0911 merged 2 commits intomainfrom
refactor/using-chunk-id-as-placeholder

Conversation

@JSerFeng
Copy link
Contributor

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

  • Tests updated (or not required).
  • Documentation updated (or not required).

Copilot AI review requested due to automatic review settings November 23, 2025 15:10
@netlify
Copy link

netlify bot commented Nov 23, 2025

Deploy Preview for rspack canceled.

Name Link
🔨 Latest commit 78a7a8a
🔍 Latest deploy log https://app.netlify.com/projects/rspack/deploys/6923d9b076a4150008f1b8d5

@github-actions github-actions bot added the release: feature release: feature related release(mr only) label Nov 23, 2025
@JSerFeng JSerFeng changed the title feat: use chunk id as the placeholder when calculating content-hash refactor: use chunk id as the placeholder when calculating content-hash Nov 23, 2025
@github-actions github-actions bot added team The issue/pr is created by the member of Rspack. release: refactor and removed release: feature release: feature related release(mr only) labels Nov 23, 2025
Copy link
Contributor

Copilot AI left a comment

Choose a reason for hiding this comment

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

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 with ChunkGraph::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_ukey map 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.

@github-actions
Copy link
Contributor

github-actions bot commented Nov 23, 2025

📦 Binary Size-limit

Comparing 78a7a8a to feat: support SRI with experiments.css and CssExtractRspackPlugin (#12239) by harpsealjs

❌ Size increased by 8.63KB from 47.63MB to 47.64MB (⬆️0.02%)

@codspeed-hq
Copy link

codspeed-hq bot commented Nov 23, 2025

CodSpeed Performance Report

Merging #12271 will not alter performance

Comparing refactor/using-chunk-id-as-placeholder (78a7a8a) with main (a082779)

Summary

✅ 17 untouched

@JSerFeng JSerFeng force-pushed the refactor/using-chunk-id-as-placeholder branch from 24ce01a to 9daef11 Compare November 23, 2025 16:12
@Timeless0911 Timeless0911 merged commit e23badc into main Nov 24, 2025
70 of 72 checks passed
@Timeless0911 Timeless0911 deleted the refactor/using-chunk-id-as-placeholder branch November 24, 2025 11:11
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

release: refactor team The issue/pr is created by the member of Rspack.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants