Skip to content

[turbopack] Fix CSS HMR on Safari#92123

Merged
lukesandberg merged 1 commit intocanaryfrom
03-30-fix_an_hmr_bug_in_safari
Mar 31, 2026
Merged

[turbopack] Fix CSS HMR on Safari#92123
lukesandberg merged 1 commit intocanaryfrom
03-30-fix_an_hmr_bug_in_safari

Conversation

@lukesandberg
Copy link
Copy Markdown
Contributor

@lukesandberg lukesandberg commented Mar 30, 2026

Fixes #91818

Regression source: Commit b7e4c6a011 ("Turbopack: transpile CHUNK_SUFFIX") introduced getChunkSuffixFromScriptSrc() which reads query strings from <script> tags. On Safari, this picks up the ?ts= param injected by the server-side cache-busting workaround in render.tsx (for WebKit #187726), baking it into ASSET_SUFFIX. This causes HMR CSS URLs to match the preloaded URL exactly, re-triggering the Safari preload cache bug and preventing style updates.

Changes:

  • dev-backend-dom.ts: Match existing <link> elements by base path (strip query string) so selectors work across HMR updates with different ?ts= values. Add Safari to the Firefox cache-busting branch so new stylesheet links always get a fresh ?ts=.
  • hmr-client.ts: Fix mergeChunkUpdates so a total update always supersedes any prior update type.

@nextjs-bot nextjs-bot added created-by: Turbopack team PRs by the Turbopack team. Turbopack Related to Turbopack with Next.js. labels Mar 30, 2026
Copy link
Copy Markdown
Contributor Author

This stack of pull requests is managed by Graphite. Learn more about stacking.

@lukesandberg lukesandberg changed the title Fix an hmr bug in safari Fix CSS HMR on Safari Mar 30, 2026
@lukesandberg lukesandberg marked this pull request as ready for review March 30, 2026 21:21
@nextjs-bot
Copy link
Copy Markdown
Contributor

Allow CI Workflow Run

  • approve CI run for commit: b84033f774c1fb0b2952929fe09672873b266030

Note: this should only be enabled once the PR is ready to go and can only be enabled by a maintainer

1 similar comment
@nextjs-bot
Copy link
Copy Markdown
Contributor

Allow CI Workflow Run

  • approve CI run for commit: b84033f774c1fb0b2952929fe09672873b266030

Note: this should only be enabled once the PR is ready to go and can only be enabled by a maintainer

@lukesandberg lukesandberg force-pushed the 03-30-fix_an_hmr_bug_in_safari branch from b84033f to 6b02071 Compare March 30, 2026 21:29
@lukesandberg lukesandberg requested a review from a team March 30, 2026 21:30
@wbinnssmith
Copy link
Copy Markdown
Member

Looks good, can we add a test to catch this?

@codspeed-hq
Copy link
Copy Markdown

codspeed-hq Bot commented Mar 30, 2026

Merging this PR will degrade performance by 4.26%

❌ 2 regressed benchmarks
✅ 15 untouched benchmarks
⏩ 3 skipped benchmarks1

⚠️ Please fix the performance issues or acknowledge them on CodSpeed.

Performance Changes

Mode Benchmark BASE HEAD Efficiency
Simulation build[lucide-react-all] 6.5 s 6.8 s -4.26%
Simulation build[joy] 1.7 s 1.8 s -3.36%

Comparing 03-30-fix_an_hmr_bug_in_safari (2da0796) with canary (d69ce48)

Open in CodSpeed

Footnotes

  1. 3 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.

@nextjs-bot
Copy link
Copy Markdown
Contributor

nextjs-bot commented Mar 30, 2026

Tests Passed

Copy link
Copy Markdown
Contributor Author

Looks good, can we add a test to catch this?

​not easily. afaict we don't have any hmr tests for safari or firefox in CI

Copy link
Copy Markdown
Contributor Author

i did manually test this with firefox and safari (and chrome) so css loading is working, but yeah it is a risk

Copy link
Copy Markdown
Contributor Author

ok, this is easy we actualyl already have css hmr tests, just not for firefox and safari

@lukesandberg lukesandberg changed the title Fix CSS HMR on Safari [turbopack] Fix CSS HMR on Safari Mar 31, 2026
@lukesandberg lukesandberg force-pushed the 03-30-fix_an_hmr_bug_in_safari branch from 6845022 to 8bb964e Compare March 31, 2026 15:04
@nextjs-bot
Copy link
Copy Markdown
Contributor

nextjs-bot commented Mar 31, 2026

Stats from current PR

✅ No significant changes detected

📊 All Metrics
📖 Metrics Glossary

Dev Server Metrics:

  • Listen = TCP port starts accepting connections
  • First Request = HTTP server returns successful response
  • Cold = Fresh build (no cache)
  • Warm = With cached build artifacts

Build Metrics:

  • Fresh = Clean build (no .next directory)
  • Cached = With existing .next directory

Change Thresholds:

  • Time: Changes < 50ms AND < 10%, OR < 2% are insignificant
  • Size: Changes < 1KB AND < 1% are insignificant
  • All other changes are flagged to catch regressions

⚡ Dev Server

Metric Canary PR Change Trend
Cold (Listen) 456ms 458ms ▆▁▁▁▁
Cold (Ready in log) 459ms 459ms ▆▁▁▁▁
Cold (First Request) 885ms 878ms ▆▂▂▂▂
Warm (Listen) 457ms 506ms ▆▁▁▁▁
Warm (Ready in log) 460ms 460ms ▆▁▁▁▁
Warm (First Request) 366ms 326ms ▄▁▁▁▁
📦 Dev Server (Webpack) (Legacy)

📦 Dev Server (Webpack)

Metric Canary PR Change Trend
Cold (Listen) 456ms 455ms ▁▁▁▁▁
Cold (Ready in log) 437ms 437ms ▁▄▁▁▁
Cold (First Request) 1.944s 1.944s ▂▃▃▁▃
Warm (Listen) 456ms 456ms ▁▁▁▁▁
Warm (Ready in log) 438ms 440ms ▁▃▁▁▁
Warm (First Request) 1.958s 1.966s ▃▅▃▁▃

⚡ Production Builds

Metric Canary PR Change Trend
Fresh Build 4.194s 4.217s ▇▁▁▁▁
Cached Build 4.221s 4.221s ▇▁▁▁▁
📦 Production Builds (Webpack) (Legacy)

📦 Production Builds (Webpack)

Metric Canary PR Change Trend
Fresh Build 14.383s 14.439s ▁▂▁▁▁
Cached Build 14.494s 14.518s ▁▂▁▁▁
node_modules Size 485 MB 485 MB █████
📦 Bundle Sizes

Bundle Sizes

⚡ Turbopack

Client

Main Bundles
Canary PR Change
0228t5fhn61xz.js gzip 162 B N/A -
02fkg8wfh0iju.js gzip 9.19 kB N/A -
050zwt5xh_0tx.js gzip 10.4 kB N/A -
06rvbj82bhyo0.js gzip 13 kB N/A -
087fzjd-gvlzv.js gzip 450 B N/A -
0cz1d0mv5g_q7.js gzip 39.4 kB 39.4 kB
0jp1sd0zat1w7.js gzip 70.8 kB N/A -
0jzr8_y9w5pdc.js gzip 155 B N/A -
0ppxcl_z43mad.js gzip 8.52 kB N/A -
19oha6-znmkcv.js gzip 8.55 kB N/A -
1cawte-uz9jt-.js gzip 169 B N/A -
1d42ohkvstrzg.js gzip 156 B N/A -
1elt1qium-r2m.css gzip 115 B 115 B
1mdeh30bxdj_x.js gzip 65.7 kB N/A -
1vgaupg3tpo14.js gzip 152 B N/A -
2_5rjb7lqxntf.js gzip 221 B 221 B
2-2f6h1hvxh7s.js gzip 157 B N/A -
219prxwxgaalc.js gzip 7.61 kB N/A -
21dx-zik_jd06.js gzip 157 B N/A -
26elcgxnn9zjd.js gzip 8.52 kB N/A -
2900hudr6gvm0.js gzip 2.28 kB N/A -
2j5xaiyot2ibs.js gzip 157 B N/A -
2lv2js3kmdeho.js gzip 8.48 kB N/A -
2osug6cdptytf.js gzip 159 B N/A -
2rehygrd36hqv.js gzip 8.58 kB N/A -
2srwswih0m9_h.js gzip 13.3 kB N/A -
2zg52pp7n9ea_.js gzip 157 B N/A -
3-p9p9mheqhzx.js gzip 8.55 kB N/A -
31030bryqpolg.js gzip 8.53 kB N/A -
31dx5nmrzzuy7.js gzip 225 B N/A -
3925v09gtu-5k.js gzip 49 kB N/A -
39x4zj5mjb4d_.js gzip 9.77 kB N/A -
3erexutz84ufd.js gzip 156 B N/A -
3k-48b78ys_vy.js gzip 10.1 kB N/A -
3m7-5rfj0avoz.js gzip 12.9 kB N/A -
3r4xu32o0h1uj.js gzip 156 B N/A -
3sd1n0vwhhao5.js gzip 157 B N/A -
3uqce_6sa526g.js gzip 8.47 kB N/A -
3yurjqk-sjs3y.js gzip 1.46 kB N/A -
40ybjx9c192n0.js gzip 13.8 kB N/A -
421vzwdt9j1b_.js gzip 5.62 kB N/A -
turbopack-0a..m7yr.js gzip 4.17 kB N/A -
turbopack-0j..hstc.js gzip 4.17 kB N/A -
turbopack-0l..ptgs.js gzip 4.18 kB N/A -
turbopack-0t.._y2k.js gzip 4.17 kB N/A -
turbopack-0u..ehjo.js gzip 4.17 kB N/A -
turbopack-29..5k-s.js gzip 4.17 kB N/A -
turbopack-2m..1g7a.js gzip 4.17 kB N/A -
turbopack-2p..gx9g.js gzip 4.17 kB N/A -
turbopack-2q..qzd2.js gzip 4.17 kB N/A -
turbopack-2q..1bgr.js gzip 4.18 kB N/A -
turbopack-3-..knag.js gzip 4.17 kB N/A -
turbopack-3f..lmdx.js gzip 4.15 kB N/A -
turbopack-3m..e0ck.js gzip 4.17 kB N/A -
turbopack-3u..3-c-.js gzip 4.17 kB N/A -
01l1buj-s4inm.js gzip N/A 155 B -
03dgzoo-qf3sm.js gzip N/A 9.19 kB -
05tx5f25dlivn.js gzip N/A 8.53 kB -
0c7ez6p2qc57f.js gzip N/A 5.62 kB -
0duvj3qk5pvgn.js gzip N/A 13.8 kB -
0egrbba9at2oy.js gzip N/A 155 B -
0m-34rm9w_wpm.js gzip N/A 7.6 kB -
0qnwuk92m8i7o.js gzip N/A 10.4 kB -
0r4wrn6n0ue2m.js gzip N/A 8.55 kB -
0rp0fodtbt_6m.js gzip N/A 8.52 kB -
0sfck-km4dl1k.js gzip N/A 8.47 kB -
0x0xuhmxzwkp8.js gzip N/A 8.47 kB -
1-wdvgxnzicj7.js gzip N/A 1.46 kB -
10lwp35j38mmf.js gzip N/A 154 B -
11u6nxujb2eg4.js gzip N/A 450 B -
1jv-o1_s-zmua.js gzip N/A 49 kB -
20v1lquiqh7un.js gzip N/A 155 B -
21_oc1ghg9t6n.js gzip N/A 167 B -
2cv61n38gcxje.js gzip N/A 154 B -
2ep2llrpeelv6.js gzip N/A 154 B -
2k9ax08cjl2id.js gzip N/A 12.9 kB -
2lms6k76q5-6m.js gzip N/A 13.3 kB -
2m_ud0ir08ji_.js gzip N/A 157 B -
2ouwrkz27lcut.js gzip N/A 155 B -
2qx4twi9i3xus.js gzip N/A 2.28 kB -
2sb5f7e9rzy9j.js gzip N/A 161 B -
2srnqic6tvxxd.js gzip N/A 8.52 kB -
2t6ec71_-3nmf.js gzip N/A 155 B -
2x4lb9krhsugf.js gzip N/A 65.7 kB -
30l7m4nayp73a.js gzip N/A 8.55 kB -
38rr7d3kfutni.js gzip N/A 13 kB -
3amuaqp3_rkar.js gzip N/A 70.8 kB -
3h_ecpiaatwgc.js gzip N/A 10.1 kB -
3ity0aahajapd.js gzip N/A 225 B -
3psn578atgc8s.js gzip N/A 153 B -
3wrhpuc-j1aw9.js gzip N/A 9.77 kB -
4316wp9aaamka.js gzip N/A 156 B -
43mlw9dy_8f02.js gzip N/A 8.58 kB -
turbopack-00..askq.js gzip N/A 4.17 kB -
turbopack-00..d_wa.js gzip N/A 4.17 kB -
turbopack-0f..9rjr.js gzip N/A 4.17 kB -
turbopack-2e..bft2.js gzip N/A 4.17 kB -
turbopack-2f..1p4f.js gzip N/A 4.19 kB -
turbopack-2k..esv3.js gzip N/A 4.17 kB -
turbopack-2l..rwtk.js gzip N/A 4.17 kB -
turbopack-2l..v7qx.js gzip N/A 4.17 kB -
turbopack-2m..4c1n.js gzip N/A 4.17 kB -
turbopack-2o..0osh.js gzip N/A 4.17 kB -
turbopack-2u..pxq-.js gzip N/A 4.15 kB -
turbopack-3c..e-df.js gzip N/A 4.17 kB -
turbopack-3m..74sh.js gzip N/A 4.17 kB -
turbopack-40..mg9s.js gzip N/A 4.17 kB -
Total 464 kB 464 kB ✅ -51 B

Server

Middleware
Canary PR Change
middleware-b..fest.js gzip 716 B 714 B
Total 716 B 714 B ✅ -2 B
Build Details
Build Manifests
Canary PR Change
_buildManifest.js gzip 434 B 431 B
Total 434 B 431 B ✅ -3 B

📦 Webpack

Client

Main Bundles
Canary PR Change
5528-HASH.js gzip 5.54 kB N/A -
6280-HASH.js gzip 60.7 kB N/A -
6335.HASH.js gzip 169 B N/A -
912-HASH.js gzip 4.59 kB N/A -
e8aec2e4-HASH.js gzip 62.8 kB N/A -
framework-HASH.js gzip 59.7 kB 59.7 kB
main-app-HASH.js gzip 256 B 255 B
main-HASH.js gzip 39.3 kB 39.2 kB
webpack-HASH.js gzip 1.68 kB 1.68 kB
262-HASH.js gzip N/A 4.59 kB -
2889.HASH.js gzip N/A 169 B -
5602-HASH.js gzip N/A 5.55 kB -
6948ada0-HASH.js gzip N/A 62.8 kB -
9544-HASH.js gzip N/A 61.4 kB -
Total 235 kB 235 kB ⚠️ +649 B
Polyfills
Canary PR Change
polyfills-HASH.js gzip 39.4 kB 39.4 kB
Total 39.4 kB 39.4 kB
Pages
Canary PR Change
_app-HASH.js gzip 194 B 194 B
_error-HASH.js gzip 183 B 180 B 🟢 3 B (-2%)
css-HASH.js gzip 331 B 330 B
dynamic-HASH.js gzip 1.81 kB 1.81 kB
edge-ssr-HASH.js gzip 256 B 256 B
head-HASH.js gzip 351 B 352 B
hooks-HASH.js gzip 384 B 383 B
image-HASH.js gzip 580 B 581 B
index-HASH.js gzip 260 B 260 B
link-HASH.js gzip 2.51 kB 2.51 kB
routerDirect..HASH.js gzip 320 B 319 B
script-HASH.js gzip 386 B 386 B
withRouter-HASH.js gzip 315 B 315 B
1afbb74e6ecf..834.css gzip 106 B 106 B
Total 7.98 kB 7.98 kB ✅ -1 B

Server

Edge SSR
Canary PR Change
edge-ssr.js gzip 125 kB 125 kB
page.js gzip 270 kB 270 kB
Total 396 kB 396 kB ⚠️ +155 B
Middleware
Canary PR Change
middleware-b..fest.js gzip 619 B 615 B
middleware-r..fest.js gzip 156 B 155 B
middleware.js gzip 44 kB 43.8 kB
edge-runtime..pack.js gzip 842 B 842 B
Total 45.6 kB 45.5 kB ✅ -133 B
Build Details
Build Manifests
Canary PR Change
_buildManifest.js gzip 715 B 718 B
Total 715 B 718 B ⚠️ +3 B
Build Cache
Canary PR Change
0.pack gzip 4.35 MB 4.34 MB 🟢 6.29 kB (0%)
index.pack gzip 110 kB 110 kB
index.pack.old gzip 110 kB 110 kB
Total 4.57 MB 4.56 MB ✅ -7.14 kB

🔄 Shared (bundler-independent)

Runtimes
Canary PR Change
app-page-exp...dev.js gzip 336 kB 336 kB
app-page-exp..prod.js gzip 186 kB 186 kB
app-page-tur...dev.js gzip 335 kB 335 kB
app-page-tur..prod.js gzip 185 kB 185 kB
app-page-tur...dev.js gzip 332 kB 332 kB
app-page-tur..prod.js gzip 183 kB 183 kB
app-page.run...dev.js gzip 332 kB 332 kB
app-page.run..prod.js gzip 184 kB 184 kB
app-route-ex...dev.js gzip 76.3 kB 76.3 kB
app-route-ex..prod.js gzip 51.9 kB 51.9 kB
app-route-tu...dev.js gzip 76.3 kB 76.3 kB
app-route-tu..prod.js gzip 51.9 kB 51.9 kB
app-route-tu...dev.js gzip 75.9 kB 75.9 kB
app-route-tu..prod.js gzip 51.7 kB 51.7 kB
app-route.ru...dev.js gzip 75.9 kB 75.9 kB
app-route.ru..prod.js gzip 51.7 kB 51.7 kB
dist_client_...dev.js gzip 324 B 324 B
dist_client_...dev.js gzip 326 B 326 B
dist_client_...dev.js gzip 318 B 318 B
dist_client_...dev.js gzip 317 B 317 B
pages-api-tu...dev.js gzip 43.5 kB 43.5 kB
pages-api-tu..prod.js gzip 33.1 kB 33.1 kB
pages-api.ru...dev.js gzip 43.5 kB 43.5 kB
pages-api.ru..prod.js gzip 33.1 kB 33.1 kB
pages-turbo....dev.js gzip 52.9 kB 52.9 kB
pages-turbo...prod.js gzip 38.7 kB 38.7 kB
pages.runtim...dev.js gzip 52.9 kB 52.9 kB
pages.runtim..prod.js gzip 38.7 kB 38.7 kB
server.runti..prod.js gzip 62.5 kB 62.5 kB
Total 2.99 MB 2.99 MB ✅ -1 B
📎 Tarball URL
https://vercel-packages.vercel.app/next/commits/2da0796b05c4431efc249c293c54e37c8e1d3da8/next

@lukesandberg lukesandberg force-pushed the 03-30-fix_an_hmr_bug_in_safari branch from 8bb964e to f3853f2 Compare March 31, 2026 16:51
@lukesandberg lukesandberg requested a review from mmastrac March 31, 2026 18:51
@lukesandberg lukesandberg force-pushed the 03-30-fix_an_hmr_bug_in_safari branch from f3853f2 to 4956ed0 Compare March 31, 2026 19:08
@graphite-app
Copy link
Copy Markdown
Contributor

graphite-app Bot commented Mar 31, 2026

Merge activity

  • Mar 31, 7:32 PM UTC: This pull request can not be added to the Graphite merge queue. Please try rebasing and resubmitting to merge when ready.
  • Mar 31, 7:32 PM UTC: Graphite disabled "merge when ready" on this PR due to: a merge conflict with the target branch; resolve the conflict and try again..

@lukesandberg lukesandberg force-pushed the 03-30-fix_an_hmr_bug_in_safari branch from 4956ed0 to 2da0796 Compare March 31, 2026 19:33
@lukesandberg lukesandberg merged commit 8be5a3c into canary Mar 31, 2026
532 of 544 checks passed
@lukesandberg lukesandberg deleted the 03-30-fix_an_hmr_bug_in_safari branch March 31, 2026 21:50
lukesandberg added a commit that referenced this pull request Mar 31, 2026
Fixes #91818

**Regression source:** Commit `b7e4c6a011` ("Turbopack: transpile
CHUNK_SUFFIX") introduced `getChunkSuffixFromScriptSrc()` which reads
query strings from `<script>` tags. On Safari, this picks up the `?ts=`
param injected by the server-side cache-busting workaround in
`render.tsx` (for [WebKit
into `ASSET_SUFFIX`. This causes HMR CSS URLs to match the preloaded URL
exactly, re-triggering the Safari preload cache bug and preventing style
updates.

**Changes:**

- **`dev-backend-dom.ts`**: Match existing `<link>` elements by base
path (strip query string) so selectors work across HMR updates with
different `?ts=` values. Add Safari to the Firefox cache-busting branch
so new stylesheet links always get a fresh `?ts=`.
- **`hmr-client.ts`**: Fix `mergeChunkUpdates` so a `total` update
always supersedes any prior update type.

(cherry picked from commit 8be5a3c)
lukesandberg added a commit that referenced this pull request Mar 31, 2026
## Summary
- Backport of #92123 to `next-16-2` release branch
- Cherry-picked the CSS HMR Safari fix and regenerated turbopack-tests
snapshot goldens for the release branch

## Test plan
- [x] `UPDATE=1 cargo nextest r -p turbopack-tests` — all 297 tests pass
- [x] `pnpm build-all` — clean build, no issues with
`generated-native.d.ts`
@github-actions github-actions Bot locked as resolved and limited conversation to collaborators Apr 16, 2026
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.

Labels

created-by: Turbopack team PRs by the Turbopack team. locked Turbopack Related to Turbopack with Next.js. type: next

Projects

None yet

Development

Successfully merging this pull request may close these issues.

16.2 broke Safari HMR for SCSS files

5 participants