Fix: Turbopack CSS HMR error when editing an unmounted merged CSS chunk (#94551)
### Fixing a bug
- [x] Related issues linked using `fixes #74749`.
- [x] Tests added (`test/development/css-hmr-unmounted-chunk`)
- [x] N/A — removes an erroneous thrown error
### What?
In `next dev` with Turbopack, editing a `.module.css` whose component
had unmounted threw `Error: No link element found for chunk
.../components_<hash>._.css` as an unhandled rejection. The edit
**silently failed to apply** — you had to reload the page manually to
see it.
### Why?
`applyChunkListUpdate` handles chunk updates asymmetrically: `'added'`
calls `loadChunkCached` (loads if missing), but `'total'` calls
`reloadChunk`, which is rejected when no `<link>` exists. When a lazy /
`dynamic(ssr:false)` component unmounts, `unloadChunk` removes its
merged-aggregate `<link>` but the chunk list stays subscribed; a later
CSS edit emits a `'total'` update for the now-unlinked aggregate →
`reloadChunk` rejects → the `'total'` branch discards the promise →
unhandled rejection, and the edit never applies.
### How?
`reloadChunk` now loads the fresh stylesheet when no `<link>` is present
(mirroring the `'added'` branch) instead of rejecting, so the edit
applies without a manual reload. Regression test reproduces with a
minimal `dynamic(ssr:false)` + 3 `React.lazy` routes fixture (red before
— the error is thrown and the edit doesn't apply; green after).
Fixes #74749
<!-- NEXT_JS_LLM_PR -->
---------
Co-authored-by:
Benjamin Woodruff <benjamin.woodruff@vercel.com>
Showing
This source diff could not be displayed because it is too large.
You can
view the blob
instead.
This source diff could not be displayed because it is too large.
You can
view the blob
instead.
This source diff could not be displayed because it is too large.
You can
view the blob
instead.
This source diff could not be displayed because it is too large.
You can
view the blob
instead.
This source diff could not be displayed because it is too large.
You can
view the blob
instead.
This source diff could not be displayed because it is too large.
You can
view the blob
instead.
Please
register
or
sign in
to comment