Skip to content

Turbopack: don't strip async-module runtime from shared runtime chunks - #96599

Merged
lukesandberg merged 3 commits into
canaryfrom
post_css_async_loader
Aug 4, 2026
Merged

lukesandberg merged 3 commits into
canaryfrom
post_css_async_loader

Conversation

@lukesandberg

@lukesandberg lukesandberg commented Aug 4, 2026 •

Copy link
Copy Markdown
Contributor

What?

Turbopack could emit a [turbopack]_runtime.js without the async-module (top-level await) machinery while chunks written next to it call __turbopack_context__.a(...), failing production builds with TypeError: __turbopack_context__.a is not a function.

Reported against 16.3 when loading a postcss.config.js. Intermittent, production only.

Why?

The runtime chunk is emitted to a fixed path, so every module graph using a chunking context writes the same file. Since #94376 the async-module machinery is dropped when a graph has no async modules — but that's decided per graph.

The Next.js node execution context is shared by every build-time JS evaluation (postcss configs, webpack loaders, next/font/google), each with its own ModuleGraph. A graph with no async modules emits a runtime without .a and clobbers the variant the postcss loader needs. The winner is assets.first() in emit_assets, which depends on emission order — hence the intermittency.

How?

Add shared_runtime_chunk to the chunking contexts and set it where one runtime is shared by several graphs, so those always emit the complete runtime. This matches the carve-out that already exists for development: in both cases a single graph can't see everything sharing the runtime. Whole-app server contexts keep the optimization.

The browser side tested RuntimeType::Development as a proxy for per-page graphs, which only works because per_page_module_graph currently is mode == Development. It now reads the real flag.

Also renames has_async_modules to include_async_module_runtime, since it's now true whenever we can't tell.

I audited the rest of .next/build/ for the same hazard: the runtime chunk (and its .map) was the only fixed-path output. Everything else is content-hashed via AssetIdent::output_name.

Testing

test/production/app-dir/turbopack-shared-runtime-async-module uses a single synchronous loader — enough on its own to produce the stripped runtime. Verified to fail without the fix and pass with it. cargo test -p turbopack-tests passes with no snapshot churn.

Follow-up, not in this PR: the conflict is silent. EmitConflictIssue is IssueSeverity::Error but never fired here, because the two runtimes weren't grouped into one emit_assets call.

@lukesandberg
lukesandberg requested a review from sampoder August 4, 2026 07:28
@lukesandberg
lukesandberg marked this pull request as ready for review August 4, 2026 07:29

@sampoder sampoder left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

change to add shared_runtime_chunk makes sense to me though its unfortunate :/

I'm 50/50 on adding per_page_module_graph it seems like it might be a little overkill.

@lukesandberg
lukesandberg marked this pull request as draft August 4, 2026 07:38
The runtime chunk is emitted to a fixed path, so every module graph using a
chunking context writes the same `[turbopack]_runtime.js`. Since #94376 the
async-module (top-level await) machinery is omitted when a graph has no async
modules, but that decision was made per-graph.

Contexts shared by several independent graphs therefore produce two different
runtimes for one path. The Next.js node execution context is shared by every
build-time JS evaluation (postcss configs, webpack loaders, next/font/google),
each with its own graph. A graph without async modules would emit a runtime
without `.a` and clobber the variant a postcss config's top-level `await` needs,
failing at build time with `__turbopack_context__.a is not a function`. Which
variant landed depended on emission order, so it reproduced intermittently.

Add `shared_runtime_chunk` to NodeJsChunkingContext and set it on the shared
node execution contexts, so those always emit the complete runtime. This
matches the existing dev carve-out: in both cases a single graph can't see
everything sharing the runtime.

On the browser side the equivalent check tested `RuntimeType::Development` as a
proxy for per-page graphs. That happens to work only because
`per_page_module_graph` is currently `mode == Development`; plumb the real flag
through instead.

Also rename `has_async_modules` to `include_async_module_runtime`, since the
value is now true whenever we can't tell rather than meaning the graph has
async modules.
Both contexts now call it `shared_runtime_chunk`. The browser side was named
after the setting that feeds it rather than the constraint it expresses.
@lukesandberg
lukesandberg force-pushed the post_css_async_loader branch from afd5b7e to f1ac0f0 Compare August 4, 2026 07:45
@github-actions

github-actions Bot commented Aug 4, 2026 •

Copy link
Copy Markdown
Contributor

Tests Passed

Commit: 534c9c9

@github-actions

github-actions Bot commented Aug 4, 2026 •

Copy link
Copy Markdown
Contributor

Stats from current PR

🔴 3 regressions

Metric Canary PR Change Trend
Turbo Build Time 5.775s 6.289s 🔴 +514ms (+9%) ▂▃▄▃▃
Turbo Build Time (cached) 2.943s 3.258s 🔴 +315ms (+11%) ▅▁▁▁▁
Webpack Warm (First Request) 3.356s 3.514s 🔴 +158ms (+5%) ▃▄▅█▅
📊 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) 812ms 813ms ✓ ▂▂▂▂▂
Cold (Ready in log) 796ms 800ms ✓ ▁▁▁▁▁
Cold (First Request) 1.333s 1.360s ✓ ▃▁▁▁▁
Warm (Listen) 814ms 813ms ✓ ▂▂▂▂▁
Warm (Ready in log) 804ms 805ms ✓ ▂▁▁▁▁
Warm (First Request) 1.338s 1.341s ✓ ▁████
📦 Dev Server (Webpack) (Legacy)

📦 Dev Server (Webpack)

Metric Canary PR Change Trend
Cold (Listen) 812ms 812ms ✓ ████▁
Cold (Ready in log) 774ms 776ms ✓ ▄▄▄▇▂
Cold (First Request) 3.301s 3.269s ✓ ▄▅▆█▅
Warm (Listen) 812ms 813ms ✓ █████
Warm (Ready in log) 778ms 805ms ✓ ▄▅▅█▄
Warm (First Request) 3.356s 3.514s 🔴 +158ms (+5%) ▃▄▅█▅

⚡ Production Builds

Metric Canary PR Change Trend
Fresh Build 5.775s 6.289s 🔴 +514ms (+9%) ▂▃▄▃▃
Cached Build 2.943s 3.258s 🔴 +315ms (+11%) ▅▁▁▁▁
📦 Production Builds (Webpack) (Legacy)

📦 Production Builds (Webpack)

Metric Canary PR Change Trend
Fresh Build 24.337s 23.909s ✓ ▅▂▄█▄
Cached Build 24.169s 24.158s ✓ ▃▅▄█▂
node_modules Size 552 MB 552 MB ✓ ▁████
📦 Bundle Sizes

Bundle Sizes

⚡ Turbopack

Client

Main Bundles
Canary PR Change
05-qx3ncawea3.js gzip 155 B N/A -
09z5quq-m03tm.js gzip 157 B N/A -
0a-p0meqxynjz.js gzip 10.3 kB N/A -
0avtke4yefj4-.js gzip 13.1 kB N/A -
0cz1d0mv5g_q7.js gzip 39.4 kB 39.4 kB ✓
0nqpqym0y3lk1.js gzip 7.44 kB N/A -
0pt5of3ch6d2u.js gzip 13.6 kB N/A -
0xnsdo-6y9r3k.js gzip 5.72 kB N/A -
0yi7is8u4covm.js gzip 8.77 kB N/A -
13h1g5-eggare.js gzip 155 B N/A -
17a_13xnvg_g4.js gzip 157 B N/A -
1elt1qium-r2m.css gzip 115 B 115 B ✓
1prv-wg6jgtt2.js gzip 8.77 kB N/A -
1rahjhhwcy3ib.js gzip 154 B N/A -
1t47vod02e_4a.js gzip 8.75 kB N/A -
1tf1phijqlx9j.js gzip 220 B 220 B ✓
1tw002sq5bo4l.js gzip 10 kB N/A -
1ut16jsaacr9-.js gzip 155 B N/A -
1vivj8wonb1vb.js gzip 161 B N/A -
1wlerik1n7zbr.js gzip 8.7 kB N/A -
1yc1-hn1hjlh7.js gzip 156 B N/A -
26xeehk9dzita.js gzip 155 B N/A -
28ldracwhxjtk.js gzip 46.3 kB N/A -
2jpx0_6n0ykra.js gzip 3.66 kB N/A -
2o3jok2ajlv1u.js gzip 155 B N/A -
2pevdqjpbf3xk.js gzip 9.45 kB N/A -
2qd2anu9eizlz.js gzip 8.75 kB N/A -
2sv39ae5_8vfj.js gzip 8.81 kB N/A -
2utx6n7w65xqa.js gzip 8.7 kB N/A -
2wdwz921uie6s.js gzip 71.4 kB N/A -
3-83nse6yhwik.js gzip 153 B N/A -
3-ukivglqkfeq.js gzip 8.78 kB N/A -
325xisqrylugu.js gzip 450 B N/A -
3ane9tg0qzdom.js gzip 168 B N/A -
3jc9ghvds1spf.js gzip 2.29 kB N/A -
3jmunbr0y3i5y.js gzip 65.6 kB N/A -
3juwkvkgvywfe.js gzip 10.6 kB N/A -
3kbove7q58uqh.js gzip 13.2 kB N/A -
3mfjeceftos56.js gzip 159 B N/A -
3qn7vntp30gaj.js gzip 1.47 kB N/A -
turbopack-0_..4ck9.js gzip 3.84 kB N/A -
turbopack-0b..hv7r.js gzip 3.84 kB N/A -
turbopack-0g..rsq5.js gzip 3.84 kB N/A -
turbopack-0y.._k5w.js gzip 3.84 kB N/A -
turbopack-15..7wbk.js gzip 3.84 kB N/A -
turbopack-17..2g0n.js gzip 3.84 kB N/A -
turbopack-1a..3t_f.js gzip 3.84 kB N/A -
turbopack-1m..3npm.js gzip 3.84 kB N/A -
turbopack-1t..l_fg.js gzip 3.84 kB N/A -
turbopack-1v.._rqs.js gzip 3.82 kB N/A -
turbopack-26..n4hm.js gzip 3.84 kB N/A -
turbopack-26..12mt.js gzip 3.84 kB N/A -
turbopack-2m..wmkm.js gzip 3.86 kB N/A -
turbopack-35..jle5.js gzip 3.85 kB N/A -
0_sfs0nf236wo.js gzip N/A 3.65 kB -
030a1njeh5b77.js gzip N/A 10 kB -
07apy8ueq20wa.js gzip N/A 157 B -
08caocbfek4_i.js gzip N/A 156 B -
0g_asir4qqohq.js gzip N/A 65.6 kB -
0ot0qt5np20h7.js gzip N/A 8.78 kB -
0qyau1fucae-s.js gzip N/A 169 B -
0rfmyt_1koql4.js gzip N/A 156 B -
11psvbmaigaiu.js gzip N/A 156 B -
12m9rr7_7cexd.js gzip N/A 8.7 kB -
186r3y_rfvr0b.js gzip N/A 8.78 kB -
19v97848yrjp7.js gzip N/A 8.81 kB -
1i5vnnubggw5l.js gzip N/A 156 B -
1nd_0rwgz2ozk.js gzip N/A 9.45 kB -
1oi9pltr_e10m.js gzip N/A 10.6 kB -
1osqg_m2p3pwd.js gzip N/A 155 B -
1rd9tzqgzsz2w.js gzip N/A 8.77 kB -
1rq1g_cwv642d.js gzip N/A 10.3 kB -
1uojw_uabeg93.js gzip N/A 450 B -
1w-7lusgyl81y.js gzip N/A 8.7 kB -
1w55luor4fqhe.js gzip N/A 161 B -
2-kydmf6v8paa.js gzip N/A 158 B -
21h56wdn9zddo.js gzip N/A 8.75 kB -
240cm9uape91v.js gzip N/A 162 B -
25kc25t9ga8lo.js gzip N/A 46.3 kB -
2flz-xxf0_v5q.js gzip N/A 158 B -
2jp1fuvxwoiaz.js gzip N/A 7.45 kB -
2ovff1533zvno.js gzip N/A 13.2 kB -
2s4z8jy0z7v93.js gzip N/A 1.46 kB -
2uoqef9eainki.js gzip N/A 71.4 kB -
2y6gb5bs4mnam.js gzip N/A 8.75 kB -
2zzexcbnj74z4.js gzip N/A 154 B -
341h71ln1jpl3.js gzip N/A 2.29 kB -
34ttpt_n7605h.js gzip N/A 5.72 kB -
36ckfq9o-ys-a.js gzip N/A 13.1 kB -
3vdh6_u50pu5t.js gzip N/A 13.6 kB -
40-xebwwe3oqt.js gzip N/A 157 B -
turbopack-04..shn8.js gzip N/A 3.86 kB -
turbopack-0p..-3-7.js gzip N/A 3.84 kB -
turbopack-1_..i5ob.js gzip N/A 3.82 kB -
turbopack-18..i-28.js gzip N/A 3.85 kB -
turbopack-1h..p9c0.js gzip N/A 3.85 kB -
turbopack-20..9yry.js gzip N/A 3.84 kB -
turbopack-27..g1nh.js gzip N/A 3.84 kB -
turbopack-2m..vdl7.js gzip N/A 3.85 kB -
turbopack-2n..vwzk.js gzip N/A 3.84 kB -
turbopack-3-..ah57.js gzip N/A 3.84 kB -
turbopack-3k..3-qn.js gzip N/A 3.84 kB -
turbopack-3k..v9l_.js gzip N/A 3.84 kB -
turbopack-3p..abgz.js gzip N/A 3.85 kB -
turbopack-3r..vviz.js gzip N/A 3.84 kB -
Total 450 kB 450 kB ⚠️ +75 B

Server

Middleware
Canary PR Change
middleware-b..fest.js gzip 772 B 774 B ✓
Total 772 B 774 B ⚠️ +2 B
Build Details
Build Manifests
Canary PR Change
_buildManifest.js gzip 433 B 433 B ✓
Total 433 B 433 B ✓
Build Cache
Canary PR Change
00000001.sst gzip 14.8 MB 14.2 MB 🟢 649 kB (-4%)
00000002.sst gzip 15.4 MB 13.5 MB 🟢 1.88 MB (-12%)
00000003.sst gzip 11.9 MB 14.7 MB 🔴 +2.87 MB (+24%)
00000004.sst gzip 13.2 MB 12.9 MB 🟢 344 kB (-3%)
00000005.sst gzip 10.3 MB 2.83 MB 🟢 7.46 MB (-72%)
00000006.sst gzip 2.83 MB 10.3 MB 🔴 +7.48 MB (+264%)
00000007.sst gzip 59 B 59 B ✓
00000008.meta gzip 89 B 89 B ✓
00000009.meta gzip 298 kB 298 kB ✓
00000010.meta gzip 299 kB 299 kB ✓
00000011.meta gzip 298 kB 298 kB ✓
00000012.sst gzip 51.2 kB 51.4 kB ✓
00000013.sst gzip 1.9 MB 1.9 MB 🔴 +5.5 kB (+0%)
00000014.sst gzip 59 B 59 B ✓
00000015.meta gzip 116 B 116 B ✓
00000016.meta gzip 324 kB 324 kB ✓
00000017.meta gzip 405 kB 405 kB ✓
00000018.sst gzip 52.1 kB 52.1 kB ✓
00000019.sst gzip 1.37 MB 1.41 MB 🔴 +35.1 kB (+3%)
00000020.sst gzip 59 B 59 B ✓
00000021.meta gzip 116 B 116 B ✓
00000022.meta gzip 324 kB 324 kB ✓
00000023.meta gzip 370 kB 370 kB ✓
00000024.sst gzip 52.1 kB 52.1 kB ✓
00000025.sst gzip 1.37 MB 1.41 MB 🔴 +35.3 kB (+3%)
00000026.sst gzip 59 B 59 B ✓
00000027.meta gzip 116 B 116 B ✓
00000028.meta gzip 324 kB 324 kB ✓
00000029.meta gzip 370 kB 370 kB ✓
00000030.sst gzip 51.4 kB 51.5 kB ✓
00000031.sst gzip 1.37 MB 1.41 MB 🔴 +35.5 kB (+3%)
00000032.sst gzip 59 B 59 B ✓
00000033.meta gzip 116 B 116 B ✓
00000034.meta gzip 324 kB 324 kB ✓
00000035.meta gzip 370 kB 370 kB ✓
00000036.sst gzip 52 kB 52.1 kB ✓
00000037.sst gzip 1.37 MB 1.41 MB 🔴 +35.4 kB (+3%)
00000038.sst gzip 59 B 59 B ✓
00000039.meta gzip 116 B 116 B ✓
00000040.meta gzip 324 kB 324 kB ✓
00000041.meta gzip 370 kB 370 kB ✓
CURRENT gzip 24 B 24 B ✓
LOG gzip 676 B 657 B 🟢 19 B (-3%)
Total 80.4 MB 80.6 MB ⚠️ +167 kB

📦 Webpack

Client

Main Bundles
Canary PR Change
3322-HASH.js gzip 65 kB N/A -
4191.HASH.js gzip 169 B N/A -
7920-HASH.js gzip 4.68 kB N/A -
9784-HASH.js gzip 5.63 kB N/A -
b1ad9f4c-HASH.js gzip 63.2 kB N/A -
framework-HASH.js gzip 59.7 kB 59.7 kB ✓
main-app-HASH.js gzip 254 B 252 B ✓
main-HASH.js gzip 40 kB 40 kB ✓
webpack-HASH.js gzip 1.68 kB 1.68 kB ✓
3577.HASH.js gzip N/A 168 B -
578-HASH.js gzip N/A 65.8 kB -
8590-HASH.js gzip N/A 5.61 kB -
9750-HASH.js gzip N/A 4.69 kB -
a8984546-HASH.js gzip N/A 63.2 kB -
Total 240 kB 241 kB ⚠️ +696 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 193 B ✓
_error-HASH.js gzip 181 B 182 B ✓
css-HASH.js gzip 334 B 331 B ✓
dynamic-HASH.js gzip 1.81 kB 1.81 kB ✓
edge-ssr-HASH.js gzip 255 B 253 B ✓
head-HASH.js gzip 349 B 351 B ✓
hooks-HASH.js gzip 382 B 384 B ✓
image-HASH.js gzip 581 B 582 B ✓
index-HASH.js gzip 260 B 259 B ✓
link-HASH.js gzip 2.48 kB 2.48 kB ✓
routerDirect..HASH.js gzip 317 B 318 B ✓
script-HASH.js gzip 384 B 386 B ✓
withRouter-HASH.js gzip 316 B 315 B ✓
1afbb74e6ecf..834.css gzip 106 B 106 B ✓
Total 7.95 kB 7.95 kB ⚠️ +1 B

Server

Edge SSR
Canary PR Change
edge-ssr.js gzip 129 kB 128 kB ✓
page.js gzip 293 kB 294 kB ✓
Total 422 kB 422 kB ⚠️ +151 B
Middleware
Canary PR Change
middleware-b..fest.js gzip 618 B 616 B ✓
middleware-r..fest.js gzip 156 B 156 B ✓
middleware.js gzip 45.8 kB 45.2 kB 🟢 552 B (-1%)
edge-runtime..pack.js gzip 842 B 842 B ✓
Total 47.4 kB 46.9 kB ✅ -554 B
Build Details
Build Manifests
Canary PR Change
_buildManifest.js gzip 718 B 718 B ✓
Total 718 B 718 B ✓
Build Cache
Canary PR Change
0.pack gzip 4.87 MB 4.86 MB 🟢 6.5 kB (0%)
index.pack gzip 122 kB 122 kB ✓
index.pack.old gzip 122 kB 122 kB ✓
Total 5.11 MB 5.1 MB ✅ -6.35 kB

🔄 Shared (bundler-independent)

Runtimes
Canary PR Change
app-page-exp...dev.js gzip 373 kB 373 kB ✓
app-page-exp..prod.js gzip 206 kB 206 kB ✓
app-page-tur...dev.js gzip 373 kB 373 kB ✓
app-page-tur..prod.js gzip 206 kB 206 kB ✓
app-page-tur...dev.js gzip 369 kB 369 kB ✓
app-page-tur..prod.js gzip 203 kB 203 kB ✓
app-page.run...dev.js gzip 369 kB 369 kB ✓
app-page.run..prod.js gzip 204 kB 204 kB ✓
app-route-ex...dev.js gzip 83 kB 83 kB ✓
app-route-ex..prod.js gzip 56.1 kB 56.1 kB ✓
app-route-tu...dev.js gzip 83.1 kB 83.1 kB ✓
app-route-tu..prod.js gzip 56.2 kB 56.2 kB ✓
app-route-tu...dev.js gzip 82.6 kB 82.6 kB ✓
app-route-tu..prod.js gzip 55.9 kB 55.9 kB ✓
app-route.ru...dev.js gzip 82.6 kB 82.6 kB ✓
app-route.ru..prod.js gzip 55.9 kB 55.9 kB ✓
dev-validati...dev.js gzip 133 kB 133 kB ✓
dev-validati...dev.js gzip 133 kB 133 kB ✓
dev-validati...dev.js gzip 131 kB 131 kB ✓
dev-validati...dev.js gzip 131 kB 131 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 46 kB 46 kB ✓
pages-api-tu..prod.js gzip 34.3 kB 34.3 kB ✓
pages-api.ru...dev.js gzip 45.9 kB 45.9 kB ✓
pages-api.ru..prod.js gzip 34.3 kB 34.3 kB ✓
pages-turbo....dev.js gzip 54.7 kB 54.7 kB ✓
pages-turbo...prod.js gzip 39.8 kB 39.8 kB ✓
pages.runtim...dev.js gzip 54.7 kB 54.7 kB ✓
pages.runtim..prod.js gzip 39.8 kB 39.8 kB ✓
server.runti..prod.js gzip 66.9 kB 66.9 kB ✓
use-cache-pr...dev.js gzip 72.1 kB 72.1 kB ✓
use-cache-pr...dev.js gzip 72.1 kB 72.1 kB ✓
use-cache-pr...dev.js gzip 70.4 kB 70.4 kB ✓
use-cache-pr...dev.js gzip 70.4 kB 70.4 kB ✓
Total 4.09 MB 4.09 MB ✓
📎 Tarball URL
https://vercel-packages.vercel.app/next/commits/534c9c9f8db58f1aedf3e9dcaf3437505e317a29/next

Commit: 534c9c9

@lukesandberg

Copy link
Copy Markdown
Contributor Author

yeah still tweaking the names. `per-page-module-graph' doesn't work in the specific case of loaders (no pages!) so 'shared_runtime_chunk' inferred from per-page-module-graph seems better

@lukesandberg
lukesandberg marked this pull request as ready for review August 4, 2026 08:19
@lukesandberg
lukesandberg enabled auto-merge (squash) August 4, 2026 08:19
The Node.js gate also matched on RuntimeType::Production, which stood in for
"the graph covers the whole app". Callers now set shared_runtime_chunk from
per_page_module_graph instead, so the check is redundant and the node gate
matches the browser one.

Plumb per_page_module_graph through ServerChunkingContextOptions, and set
shared_runtime_chunk on the turbopack-cli dev ExecutionContext, which is shared
by every build-time evaluation and was previously only covered by the
RuntimeType::Development branch.

Dev graphs that are self-contained now get the optimization too, which the
RuntimeType check previously blocked: the debug-ids/node snapshot drops 132
lines of async-module machinery its graph never uses.
@lukesandberg
lukesandberg marked this pull request as draft August 4, 2026 08:20
auto-merge was automatically disabled August 4, 2026 08:20

Pull request was converted to draft

@lukesandberg
lukesandberg marked this pull request as ready for review August 4, 2026 08:20
@lukesandberg
lukesandberg enabled auto-merge (squash) August 4, 2026 08:21
@lukesandberg
lukesandberg merged commit a75ece1 into canary Aug 4, 2026
131 checks passed
@lukesandberg
lukesandberg deleted the post_css_async_loader branch August 4, 2026 08:48
lukesandberg added a commit that referenced this pull request Aug 4, 2026
…ntime chunks (#96653)

Backports [#96599](#96599)
("Turbopack: don't strip async-module runtime from shared runtime
chunks") to `next-16-3`.


<!-- NEXT_JS_LLM -->
m-kawafuji pushed a commit to m-kawafuji/next.js that referenced this pull request Aug 8, 2026
vercel#96599)

### What?

Turbopack could emit a `[turbopack]_runtime.js` without the async-module
(top-level await) machinery while chunks written next to it call
`__turbopack_context__.a(...)`, failing production builds with
`TypeError: __turbopack_context__.a is not a function`.

Reported against 16.3 when loading a `postcss.config.js`. Intermittent,
production only.

### Why?

The runtime chunk is emitted to a fixed path, so every module graph
using a chunking context writes the same file. Since vercel#94376 the
async-module machinery is dropped when a graph has no async modules —
but that's decided per graph.

The Next.js node execution context is shared by every build-time JS
evaluation (postcss configs, webpack loaders, `next/font/google`), each
with its own `ModuleGraph`. A graph with no async modules emits a
runtime without `.a` and clobbers the variant the postcss loader needs.
The winner is `assets.first()` in `emit_assets`, which depends on
emission order — hence the intermittency.

### How?

Add `shared_runtime_chunk` to the chunking contexts and set it where one
runtime is shared by several graphs, so those always emit the complete
runtime. This matches the carve-out that already exists for development:
in both cases a single graph can't see everything sharing the runtime.
Whole-app server contexts keep the optimization.

The browser side tested `RuntimeType::Development` as a proxy for
per-page graphs, which only works because `per_page_module_graph`
currently *is* `mode == Development`. It now reads the real flag.

Also renames `has_async_modules` to `include_async_module_runtime`,
since it's now true whenever we can't tell.

I audited the rest of `.next/build/` for the same hazard: the runtime
chunk (and its `.map`) was the only fixed-path output. Everything else
is content-hashed via `AssetIdent::output_name`.

### Testing

`test/production/app-dir/turbopack-shared-runtime-async-module` uses a
single synchronous loader — enough on its own to produce the stripped
runtime. Verified to fail without the fix and pass with it. `cargo test
-p turbopack-tests` passes with no snapshot churn.

Follow-up, not in this PR: the conflict is silent. `EmitConflictIssue`
is `IssueSeverity::Error` but never fired here, because the two runtimes
weren't grouped into one `emit_assets` call.
N2D4 added a commit to hexclave/hexclave that referenced this pull request Aug 14, 2026
…1959)

Dashboard production builds fail intermittently with:

```
./apps/dashboard/src/app/globals.css
Error: Error evaluating Node.js code
TypeError: __turbopack_context__.a is not a function
    at mod (apps/dashboard/postcss.config.js_.loader.mjs:11:31)
```

## Root cause

An upstream Turbopack bug, not our cache configuration.

Turbopack emits the shared runtime chunk to one fixed path
(`.next/build/chunks/[turbopack]_runtime.js`), but strips the
async-module machinery per module graph. Next's build-time Node.js
evaluation context is shared across graphs (postcss config, loaders,
next-font), so a graph containing no async modules emits a runtime
without `.a` and overwrites the one the postcss loader calls. Which
version wins depends on emission order, hence the intermittency and the
"production only" signature.

Fixed upstream by vercel/next.js#96599, backported in #96653, released
in `[email protected]`.

## Changes

- `next` 16.3.0 → 16.3.1 in the four apps that pin it directly
(dashboard, mcp, internal-tool, skills).
- `minimumReleaseAgeExclude` entries moved from 16.3.0 to 16.3.1
(`minimumReleaseAge` itself unchanged). 16.3.1 is younger than the 7-day
window; taking it early was explicitly approved because it carries this
fix.
- `turbo.json`: build outputs are now `.next/**` + `!.next/cache/**` +
`!.next/dev/**`, matching turborepo's own `examples/basic`. Independent
of the bug — Turbopack's persistent cache under `.next/cache` was being
packed into turbo artifacts (610 MB → 54 MB for the dashboard build),
and neither cache state nor dev-server state (`.next/dev`, which `next
build` never writes) belongs in a build artifact.

## Validation

Upstream regression fixture
(`test/production/app-dir/turbopack-shared-runtime-async-module` from
the fix commit), checking the emitted runtime chunk for the
`asyncModule` machinery:

| next | `asyncModule` in emitted runtime |
| --- | --- |
| 16.3.0 | absent |
| 16.3.1 | present |

That is the mechanism, fail → pass.

Dashboard: 20 consecutive production builds with a warm `.next` on each
version — 0 failures on both, all 40 runs emitted a runtime containing
`asyncModule`. The failure is emission-order dependent and did not
surface locally in either arm, so this is a "no regression" signal, not
a local reproduction of the failure. `typecheck`, `lint`, `build`,
`build:rde-standalone` pass, as do builds of the three other upgraded
apps.

Link to Devin session:
https://app.devin.ai/sessions/f9469ed89c4d4d668f53c6622e404984
Requested by: @N2D4

---------

Co-authored-by: Devin AI <158243242+devin-ai-integration[bot]@users.noreply.github.com>
@github-actions github-actions Bot added the locked label Sep 6, 2026
@github-actions github-actions Bot locked as resolved and limited conversation to collaborators Sep 6, 2026
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.

Labels

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants