Skip to content

fix(hmr): validate chunk versions before installation - #16360

Merged
JSerFeng merged 12 commits into
mainfrom
fy/hmr-chunk-version-check
Nov 2, 2026
Merged

JSerFeng merged 12 commits into
mainfrom
fy/hmr-chunk-version-check

Conversation

@JSerFeng

@JSerFeng JSerFeng commented Oct 30, 2026 •

Copy link
Copy Markdown
Contributor

Motivation

A dynamic import can receive a newer chunk before HMR catches up, or an old response can arrive after an update. Checking only after installation lets incompatible factories or chunk runtime code affect the running application.

Validate per-chunk JavaScript versions before installation, following webpack's versioning strategy. Unrelated compilations should not rewrite unchanged chunk assets.

Changes

  • Hash async-loadable chunks from their module IDs and module hashes. JSONP, importScripts, require, async-node and ESM loaders validate responses before installing factories, executing chunk runtime code or marking chunks loaded.
  • Patch the expected version map through RuntimeModule.generate_update. No manifest fields or loaded-version table are added.
  • Follow webpack by wrapping each module's require.e in the HMR runtime; remove the separate hmrE runtime global. Rspack runtime mode uses the same wrapper through its module context. Concurrent callers share one retry chain per in-flight chunk. Compatible loads complete normally; a version mismatch waits for HMR progress and retries. Only the current downloads block prepare, including any hot-update downloads issued by the ensure handlers.
  • Keep ordinary chunk URLs unchanged, including retries. Native ESM's existing same-URL module cache remains outside this PR: a cached stale response is rejected without installing its factories, but automatic recovery is not guaranteed.
  • Bound the wait for HMR with the existing output.chunkLoadTimeout. A status handler awaiting that import can otherwise form a circular dependency. Timeout rejects the import with ChunkLoadError; ready-handler rejections also propagate to hot.check(). Waiting listeners and timers are removed. A handler that catches the error can let HMR finish and import again afterwards.
  • Keep the PR directly based on main, without depending on fix(hmr): propagate update preparation failures #16383. The ready-handler promise handling is limited to completing or rejecting the pending check; the separate loader-state fix remains in fix(hmr): preserve chunk loading state across runtime updates #16382.

Three fixtures cover version-map patches, synchronous loaders, and async loading schedules in both runtime modes. The compact status-handler cases cover compatible responses, future responses with automatic/manual apply, catching the timeout, and an unrelated asynchronous handler. Generated snapshots and the WebRunner asset-cache adjustment remain included.

Validation:

  • All 120 focused HMR regressions and 151 HMR snapshot cases pass. The cross-origin loading E2E passes with its original exact-URL assertion. The ESM test transport caches namespaces by request URL; the late-response case checks rejection without executing stale factories or hanging.
  • Of 2,808 combinations in the independent race matrix, 2,754 recover successfully. The remaining 54 use native ESM with stable filenames and cached old modules; they reject rather than hang. All web, async-node, and contenthash-filename cases pass. ESM cache recovery is deferred separately.
  • 18 additional external cases covering check/prepare handlers and an import initiating its own catch-up reject without hanging or producing unhandled rejections.
  • JavaScript syntax and whitespace checks pass. This revision changes no Rust source.

@JSerFeng
JSerFeng requested a review from LingyuCoder as a code owner October 30, 2026 04:57
@chatgpt-codex-connector

chatgpt-codex-connector Bot commented Oct 30, 2026 •

Copy link
Copy Markdown

Codex Review Summary

This comment shows the latest Codex review activity on this pull request.

Review Status Commit Review trigger
📝 Code Review ✅ Completed 2026-11-02T07:36:25.232669Z 8d14643 New commits
🔒 Security Review ✅ Completed 2026-11-02T07:36:13.165485Z 8d14643 New commits
ℹ️ About Codex in GitHub

Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you

  • Open a pull request for review
  • Mark a draft as ready
  • Comment "@codex review" or "@codex security review".

Codex reacts with 👀 while any review is running, comments if it has suggestions, and reacts with 👍 once all reviews finish with no findings.

@chatgpt-codex-connector

Copy link
Copy Markdown

You have reached your Codex usage limits for code reviews. You can see your limits in the Codex usage dashboard.
To continue using code reviews, add credits to your account and enable them for code reviews in your settings.

@cloudflare-workers-and-pages

cloudflare-workers-and-pages Bot commented Oct 30, 2026 •

Copy link
Copy Markdown

Deploying rspack with  Cloudflare Pages  Cloudflare Pages

Latest commit: d9cee64
Status: ✅  Deploy successful!
Preview URL: https://630122f9.rspack-v2.pages.dev
Branch Preview URL: https://fy-hmr-chunk-version-check.rspack-v2.pages.dev

View logs

@github-actions

github-actions Bot commented Oct 30, 2026 •

Copy link
Copy Markdown
Contributor

📦 Binary Size-limit

Comparing 1a1125d to chore(deps): upgrade Rstack CLI to v0.9.0 (#16396) by Jiahan Chen

❌ Size increased by 48.13KB from 67.95MB to 67.99MB (⬆️0.07%)

@github-actions

github-actions Bot commented Oct 30, 2026 •

Copy link
Copy Markdown
Contributor

Rsdoctor Bundle Diff Analysis

Found 5 projects in monorepo, 0 projects with changes.

📊 Quick Summary
Project Total Size Gzip Size Change Gzip Change
popular-libs 1.7 MB 541.6 KB 0 0
react-10k 5.4 MB 1.3 MB 0 0
react-1k 827.5 KB 225.2 KB 0 0
react-5k 2.6 MB 670.6 KB 0 0
ui-components 4.7 MB 1.4 MB 0 0

Generated by Rsdoctor GitHub Action

@codspeed

codspeed Bot commented Oct 30, 2026 •

Copy link
Copy Markdown
Contributor

Merging this PR will not alter performance

✅ 57 untouched benchmarks
⏩ 47 skipped benchmarks1


Comparing fy/hmr-chunk-version-check (1a1125d) with main (a62ae4e)

Open in CodSpeed

Footnotes

  1. 47 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. ↩

@JSerFeng JSerFeng changed the title fix(hmr): check chunk versions before resolving dynamic imports fix(hmr): validate compilation hashes before installing chunks Oct 30, 2026
@JSerFeng JSerFeng changed the title fix(hmr): validate compilation hashes before installing chunks fix(hmr): validate chunk versions before installation Oct 31, 2026
@JSerFeng
JSerFeng changed the base branch from main to fy/fix-hmr-update-preparation October 31, 2026 20:11
@JSerFeng
JSerFeng force-pushed the fy/hmr-chunk-version-check branch from 29e4ba2 to c699287 Compare October 31, 2026 21:34
@JSerFeng
JSerFeng changed the base branch from fy/fix-hmr-update-preparation to main October 31, 2026 21:34
@JSerFeng
JSerFeng force-pushed the fy/hmr-chunk-version-check branch from c699287 to bb1bba9 Compare October 31, 2026 21:41
@JSerFeng

JSerFeng commented Nov 2, 2026

Copy link
Copy Markdown
Contributor Author

@codex review

@chatgpt-codex-connector

Copy link
Copy Markdown

Codex Review: Didn't find any major issues. Bravo.

Reviewed commit: 0a0048456d

ℹ️ About Codex in GitHub

Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you

  • Open a pull request for review
  • Mark a draft as ready
  • Comment "@codex review".

If Codex has suggestions, it will comment; otherwise it will react with 👍.

Codex can also answer questions or update the PR. Try commenting "@codex address that feedback".

@chatgpt-codex-connector

Copy link
Copy Markdown

🛡️ Codex Security Review · Automatically triggered

Security review completed. No security issues were found in this pull request.

Reviewed commit: 0a0048456d

View security finding report

Only the user who started this review can view the report in Codex.

ℹ️ About Codex security reviews in GitHub

This is an experimental Codex feature. Security reviews are triggered when:

  • You comment "@codex security review"
  • A regular code review gets triggered (for example, "@codex review" or when a PR is opened), and you’re opted in so security review runs alongside code review

Once complete, Codex will leave suggestions, or a comment if no findings are found.

Co-authored-by: JSerFeng <57202839+JSerFeng@users.noreply.github.com>
Copilot AI requested a review from stormslowly as a code owner November 2, 2026 08:32
@CLAassistant

Copy link
Copy Markdown

CLA assistant check
Thank you for your submission! We really appreciate it. Like many open source projects, we ask that you all sign our Contributor License Agreement before we can accept your contribution.
1 out of 2 committers have signed the CLA.

✅ JSerFeng
❌ Copilot
You have signed the CLA already but the status is still pending? Let us recheck it.

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.

4 participants