Skip to content

fix: sometimes entry chunk hash not changes with full hash runtime modules#9986

Merged
ahabhgk merged 3 commits intomainfrom
fix/initial-chunk-hash
Apr 14, 2025
Merged

fix: sometimes entry chunk hash not changes with full hash runtime modules#9986
ahabhgk merged 3 commits intomainfrom
fix/initial-chunk-hash

Conversation

@LingyuCoder
Copy link
Copy Markdown
Contributor

@LingyuCoder LingyuCoder commented Apr 11, 2025

Summary

fix #9985

In this repro https://github.com/hikerpig/module-runtimechunk-repro, the combination of chunkFormat: module and runtimeChunk: true causes the entry chunk to import the runtime chunk via import __webpack_require__ from "./runtime~main.857eaa3b.js";.

This leads to a situation, when relying on full hash (such as the entry injected by the dev server), during incremental builds in the dev mode, changes of the full hash will cause changes in the content of the runtime chunk. If the filename of the runtime chunk contains [contenthash], then its final filename will change. At this time, due to the above mentioned import statement, the content of the entry chunk will also change, and consequently, its [contenthash] will change.

However, when rspack calculates the contenthash of a chunk, it doesn't take this scenario into account. Because the entry chunk itself has no real relation to these changes, and the import statement is startup code injected during the code generation of the chunk. So when these contents change, the contenthash and chunkhash of the entry chunk in rspack won't change. As a result, the chunk code generation cache takes effect, and the runtime chunk from the previous compilation is referenced.

In Webpack, when adding a runtime module, the runtime module is associated with this chunk. When handling the chunk hash, for normal chunks, it also checks whether they contain full hash modules just like runtime chunks, and then includes the chunk in the hash update process of full hash chunks. However, in rspack, this associative relationship doesn't exist, and the chunk hash only deals with the full hash update of runtime chunks.

So this PR only applies to the scenarios of commonjs and module chunkFormats. If they introduce the loading statement of the runtime chunk, then this entry chunk will be added to the full - hash update, causing the cache of this entry chunk to become invalid, thus fixing this issue.

However, in the new incremental, Mutation::ModuleSetHashes only affects the chunks associated with the module. This causes the chunk hashing process to be skipped, and the problem still persists. I haven't found a good solution to this.

Checklist

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

@github-actions github-actions bot added release: bug fix release: bug related release(mr only) team The issue/pr is created by the member of Rspack. labels Apr 11, 2025
@netlify
Copy link
Copy Markdown

netlify bot commented Apr 11, 2025

Deploy Preview for rspack canceled.

Name Link
🔨 Latest commit de28e55
🔍 Latest deploy log https://app.netlify.com/sites/rspack/deploys/67f8ef943e33e1000875d93a

@LingyuCoder LingyuCoder changed the title fix: chunk hash not change with full hash runtime modules fix: sometimes entry chunk hash not changes with full hash runtime modules Apr 11, 2025
@codspeed-hq
Copy link
Copy Markdown

codspeed-hq bot commented Apr 11, 2025

CodSpeed Performance Report

Merging #9986 will not alter performance

Comparing fix/initial-chunk-hash (de28e55) with main (c881e92)

🎉 Hooray! codspeed-rust just leveled up to 2.7.2!

A heads-up, this is a breaking change and it might affect your current performance baseline a bit. But here's the exciting part - it's packed with new, cool features and promises improved result stability 🥳!
Curious about what's new? Visit our releases page to delve into all the awesome details about this new version.

Summary

✅ 11 untouched benchmarks

Copy link
Copy Markdown
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.

Copilot reviewed 12 out of 12 changed files in this pull request and generated no comments.

@LingyuCoder LingyuCoder requested a review from Copilot April 11, 2025 10:29
Copy link
Copy Markdown
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.

Copilot reviewed 12 out of 12 changed files in this pull request and generated no comments.

Comments suppressed due to low confidence (1)

crates/rspack_plugin_runtime/src/helpers.rs:150

  • [nitpick] Consider revising the error message from 'should has entry point ukey' to 'should have an entry point ukey' for improved grammatical clarity.
.next().ok_or_else(|| error!("should has entry point ukey"))?;

dist: path.resolve(__dirname, `./js/new-incremental/watch`)
dist: path.resolve(__dirname, `./js/new-incremental/watch`),
// TODO: fix this test case
exclude: [/runtimeChunkFullHash/]
Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

This case can not work with new incremental, perhaps we need to handle this in https://github.com/web-infra-dev/rspack/blob/main/crates/rspack_core/src/incremental/mutations.rs#L146-L148 @ahabhgk

@LingyuCoder LingyuCoder marked this pull request as ready for review April 11, 2025 10:33
@ahabhgk ahabhgk enabled auto-merge (squash) April 14, 2025 05:04
@ahabhgk ahabhgk merged commit a59834e into main Apr 14, 2025
27 checks passed
@ahabhgk ahabhgk deleted the fix/initial-chunk-hash branch April 14, 2025 05:04
@h-a-n-a h-a-n-a mentioned this pull request Apr 15, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

release: bug fix release: bug related release(mr only) team The issue/pr is created by the member of Rspack.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

[Bug]: sometimes content hash of runtime chunk changes but code of chunk loading do not change

3 participants