#15887·rspack

[Bug]: Delayed dynamic import overwrites a completed HMR update, including with content-hashed chunks

Author: matthewdavis-oaiCreated Sep 25, 2026Updated Sep 26, 2026

Reproduction

Rspack 2.2.6 can successfully apply an update and then install an older factory from a dynamic import that was already in flight. A subsequent import returns the old exports without an error.

Standalone reproduction, tested with Node 24.19.0 and Chromium through Playwright 1.61.1:

bash
npm install
npx playwright install chromium
npm run repro
npm run control

The fixture uses ESM chunk loading and [id].[contenthash].js, with old assets retained. It has no framework or lazy-compilation plugin. The reproduction command exits successfully when it observes the defect; the control delivers the original response before the edit.

  1. Start import("./feature.js") while HMR is idle. The server reads and holds the v1 chunk response.
  2. Edit the feature to v2 and await the watch rebuild.
  3. Await module.hot.check(true). It reports the feature updated and returns to idle; the hot-update payload contains v2.
  4. Release the held v1 response.
  5. Both the pending import and a later import return v1. The control's later import returns v2.

Expected: once the update has applied, an older pending chunk must not restore the old factory. Waiting for that chunk before applying the update is an acceptable ordering; the pending import itself may initially return v1.

Source and candidate fix

trackBlockingPromise at the inspected commit only counts imports started in prepare or ready. Imports started in idle are omitted, allowing HMR to finish before their normal chunk installation. Content hashing preserves the old response's identity but does not prevent that response from installing its factory later. The runtime source condition remains on this commit; the browser reproduction was run against 2.2.6.

The Rspack 2.2.6 / Rsbuild 2.2.8 source-only reproduction and patch package contains patches/rspack-hmr-inflight.patch and the focused commands in README section 1:

bash
node hmr-inflight/repro.cjs
node hmr-inflight/repro.cjs --hook
node hmr-inflight/repro.cjs --hook --mutable
node hmr-inflight/repro.cjs --hook --manual --ready-import --reject

The candidate counts imports started while idle and holds readiness until both pending imports and initial hot-update downloads finish. Counting imports alone is insufficient: an import settling during prepare must not announce ready while update downloads are outstanding.

Browser controls passed for hashed/mutable filenames and manual apply with a ready-handler import and rejected request. A compiled candidate also passed without the runtime hook, plus ten deterministic schedules against its emitted runtime covering download ordering, manual apply, asynchronous status handlers, rejected operations and synchronous handler throws. The package documents exact commands and validation limits; it contains no native binary.

A separate local candidate based on Rspack 2.2.7, with Rsbuild 2.2.9, passed 10 readiness and 10 adversarial schedules against an extracted HMR fragment from its emitted runtime. These use deterministic mocked downloads, not a new execution of the browser reproduction above. They cover idle imports, update-download ordering, ready-handler imports, rejection, synchronous throws, and terminal abort/fail states. No JavaScript ordering hook was added.

That candidate is a custom host-linker release build, native SHA-256 b6475ccf0c3e67cc795d21ca4f745c40e5945529f8894ab5cd14445cbf090df2, containing combined local patches; it is not the stock 2.2.7 distribution or a performance benchmark. The linked public package remains pinned to 2.2.6 / 2.2.8 and does not contain this newer validation set.

Long-lived imports can delay application under this approach. The separate case where a mutable URL serves a newer chunk with new dependencies to an old runtime remains outside this patch.

Originally noted in #15842; separated here because this reproduction does not require lazy compilation or the async-owner code-generation change.