Skip to content

Show inner "use cache" as cause of nested-dynamic cache error#93707

Open
unstubbable wants to merge 1 commit intohl/do-not-throw-invalid-dynamic-usage-errors-in-devfrom
hl/nested-short-cache-life-stacks
Open

Show inner "use cache" as cause of nested-dynamic cache error#93707
unstubbable wants to merge 1 commit intohl/do-not-throw-invalid-dynamic-usage-errors-in-devfrom
hl/nested-short-cache-life-stacks

Conversation

@unstubbable
Copy link
Copy Markdown
Contributor

@unstubbable unstubbable commented May 8, 2026

When a "use cache" propagated a dynamic cache life (revalidate: 0 or expire under 5 minutes) to a parent without an explicit cacheLife, the resulting error pointed only at the outer cache invocation. With the inner cache's call site missing, tracing which nested cache was responsible meant reading through the outer's body — fine when it's local code, much harder when the dynamism comes from a nested cache buried in a third-party dependency.

This change attaches the inner invocation as cause of the error, so the dev redbox and the build log show two stacks: the outer that threw, and the inner that propagated the dynamic life.

The inner call site has to be captured eagerly while cache() is still on the synchronous stack, because we only learn whether the inner resolved dynamic asynchronously — after collectResult finishes and propagateCacheEntryMetadata runs — and by then the inner's frames are no longer on the JS stack. We only construct the eager Error when the parent is itself a public "use cache" (the only case where this entry could become a propagated origin), so top-level caches skip the allocation. The eager Error is held on cacheContext.dynamicNestedCacheError; once propagation knows the inner resolved dynamic, it's copied onto the outer store's same-named field, then carried through the outer's own collectResult into its RDC entry — which the throw site finally reads back as cause. We keep the first dynamic child — the immediate origin from the throwing cache's perspective.

The two nested-dynamic cache error messages also get a small cleanup: each used to write "use cache" two different ways within the same sentence (bare and backticked); both now write it the same way.

localhost_3000_use-cache-low-expire_nested (1)

Copy link
Copy Markdown
Contributor Author

unstubbable commented May 8, 2026

Warning

This pull request is not mergeable via GitHub because a downstack PR is open. Once all requirements are satisfied, merge this PR as a stack on Graphite.
Learn more

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

@github-actions
Copy link
Copy Markdown
Contributor

github-actions Bot commented May 8, 2026

Tests Passed

Commit: ff34f00

@unstubbable unstubbable force-pushed the hl/nested-short-cache-life-stacks branch 4 times, most recently from b1a9438 to 74aad9e Compare May 9, 2026 11:18
@github-actions
Copy link
Copy Markdown
Contributor

github-actions Bot commented May 9, 2026

Stats from current PR

🔴 1 regression

Metric Canary PR Change Trend
node_modules Size 505 MB 505 MB 🔴 +91.7 kB (+0%) ▂▂███
📊 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) 810ms 810ms ████▁
Cold (Ready in log) 783ms 781ms ▆▇▇▇▁
Cold (First Request) 1.216s 1.210s ▂▅▆▃▂
Warm (Listen) 811ms 810ms ▃▃█▁█
Warm (Ready in log) 783ms 782ms ▁▃▂▃█
Warm (First Request) 595ms 595ms ▂▄▃▃█
📦 Dev Server (Webpack) (Legacy)

📦 Dev Server (Webpack)

Metric Canary PR Change Trend
Cold (Listen) 812ms 810ms █████
Cold (Ready in log) 787ms 787ms ██▇▇▆
Cold (First Request) 3.179s 3.167s ██▆▄▄
Warm (Listen) 810ms 810ms █████
Warm (Ready in log) 789ms 785ms ██▇▆▆
Warm (First Request) 3.209s 3.244s ▇█▄▄▃

⚡ Production Builds

Metric Canary PR Change Trend
Fresh Build 4.698s 4.672s ▁▅█▄▅
Cached Build 4.718s 4.663s ▃▄█▅▃
📦 Production Builds (Webpack) (Legacy)

📦 Production Builds (Webpack)

Metric Canary PR Change Trend
Fresh Build 23.775s 23.548s ███▅▂
Cached Build 23.690s 23.596s ▆█▆▄▁
node_modules Size 505 MB 505 MB 🔴 +91.7 kB (+0%) ▂▂███
📦 Bundle Sizes

Bundle Sizes

⚡ Turbopack

Client

Main Bundles
Canary PR Change
02ffxdsf7jx6t.js gzip 157 B N/A -
04hm05ar7kldw.js gzip 5.73 kB N/A -
06gsfi_m0xcyn.js gzip 161 B N/A -
0cz1d0mv5g_q7.js gzip 39.4 kB 39.4 kB
0dvitrl5zg37g.js gzip 8.82 kB N/A -
0nqh1n0j6mmm9.js gzip 49.5 kB N/A -
0sf7ysou-72zd.js gzip 8.71 kB N/A -
0v8jdh7rfnazz.js gzip 168 B N/A -
0vlzv-0h09401.js gzip 157 B N/A -
157abun3hwc_s.js gzip 10.3 kB N/A -
1elt1qium-r2m.css gzip 115 B 115 B
1jj68jv9537mc.js gzip 13.8 kB N/A -
1jpaub6y8xlfr.js gzip 2.3 kB N/A -
1m_wvg6gcvtvp.js gzip 153 B N/A -
1nxttibwatm2u.js gzip 154 B N/A -
1ot0mvscrc_uf.js gzip 233 B N/A -
1qtyyb6p_e4gx.js gzip 157 B N/A -
1s_pjvrtol87_.js gzip 154 B N/A -
2_m3xv2uq3sjc.js gzip 1.46 kB N/A -
24y34mwgrkqp4.js gzip 8.78 kB N/A -
2c-fd4y1zozz8.js gzip 8.79 kB N/A -
2d7416h_xd36x.js gzip 8.71 kB N/A -
2extn3odmmem_.js gzip 12.9 kB N/A -
2fyhyy7niw9r6.js gzip 7.61 kB N/A -
2lyuhit6rn8fy.js gzip 9.44 kB N/A -
2mmpp6w4-izb4.js gzip 153 B N/A -
2q0gr8wfr3jwl.js gzip 8.77 kB N/A -
2siu6f4ud8a_d.js gzip 70.8 kB N/A -
2t9e75oz6r0zp.js gzip 8.76 kB N/A -
2uku_olcn15b7.js gzip 8.79 kB N/A -
2uqsb--492dc1.js gzip 155 B N/A -
2vbmj47sfqmzq.js gzip 163 B N/A -
30r8mm-46bdqy.js gzip 220 B 220 B
3b5jq4uo44l33.js gzip 153 B N/A -
3inab2jybr4k9.js gzip 450 B N/A -
3jkm5tdjvaf_q.js gzip 13.1 kB N/A -
3jrk4uk0ba4tf.js gzip 155 B N/A -
3mt67agm5wp40.js gzip 10.6 kB N/A -
3qsii5phyoxm4.js gzip 65.5 kB N/A -
3saabek4kohwi.js gzip 10 kB N/A -
4189xmby9yu1p.js gzip 13.6 kB N/A -
turbopack-02..tg95.js gzip 4.2 kB N/A -
turbopack-03..9ed_.js gzip 4.18 kB N/A -
turbopack-0g..4wf2.js gzip 4.2 kB N/A -
turbopack-0h..e2ij.js gzip 4.2 kB N/A -
turbopack-0m..zw9w.js gzip 4.21 kB N/A -
turbopack-1-..74jp.js gzip 4.2 kB N/A -
turbopack-21..u9gx.js gzip 4.2 kB N/A -
turbopack-2f..ag01.js gzip 4.2 kB N/A -
turbopack-2r..7z8o.js gzip 4.2 kB N/A -
turbopack-30..cuse.js gzip 4.2 kB N/A -
turbopack-32..j9tm.js gzip 4.19 kB N/A -
turbopack-3k..73s6.js gzip 4.2 kB N/A -
turbopack-3z..s17g.js gzip 4.2 kB N/A -
turbopack-3z..ktve.js gzip 4.2 kB N/A -
0_i7nqgx23st7.js gzip N/A 10 kB -
00ikwr42k-__-.js gzip N/A 156 B -
05e40c15cx1dd.js gzip N/A 7.61 kB -
06puhytyxk31p.js gzip N/A 8.82 kB -
09ublx8mllt2b.js gzip N/A 156 B -
0lbxi6fe7sfob.js gzip N/A 70.8 kB -
0m34gln_kt4fg.js gzip N/A 5.73 kB -
0odav8mrbp0d_.js gzip N/A 158 B -
1g3q1ww01thnl.js gzip N/A 2.3 kB -
1hraqxuiymq6v.js gzip N/A 8.79 kB -
1l9un1sl77287.js gzip N/A 1.46 kB -
1lxerkgn_dyfu.js gzip N/A 158 B -
1p5k3-0w6gzt7.js gzip N/A 153 B -
1vmnes_3wll3c.js gzip N/A 156 B -
21-eavqb1k_36.js gzip N/A 13.9 kB -
2147zgtf14z-q.js gzip N/A 234 B -
23bz3xsg-5-1s.js gzip N/A 8.71 kB -
27441mytv7pbm.js gzip N/A 9.43 kB -
2b7huw5v774wp.js gzip N/A 169 B -
2cjkwjgm1zcfs.js gzip N/A 8.71 kB -
2jgw6-wx5cpt4.js gzip N/A 161 B -
2scd8zaoyb8md.js gzip N/A 8.79 kB -
2st_qs6p_9us0.js gzip N/A 13.1 kB -
2vzmb1tzids9v.js gzip N/A 159 B -
2xj1pr8x83eec.js gzip N/A 155 B -
2zo2exm1d8qj1.js gzip N/A 13.6 kB -
31d304nyh0qnr.js gzip N/A 49.5 kB -
3881z1dii6e92.js gzip N/A 156 B -
3gbgjk34zetxr.js gzip N/A 65.6 kB -
3hn75zuxly9az.js gzip N/A 10.3 kB -
3hqh7m128tvsn.js gzip N/A 8.77 kB -
3hqti_t-zy1x4.js gzip N/A 449 B -
3mnawenie1flm.js gzip N/A 8.76 kB -
3ubsozlu6zs38.js gzip N/A 10.6 kB -
3z6tdtry-oasp.js gzip N/A 155 B -
41mf-x3mmsxae.js gzip N/A 12.9 kB -
42twk6cn4g_is.js gzip N/A 154 B -
43iwfqjnx1cy_.js gzip N/A 8.78 kB -
turbopack-0n..v3i7.js gzip N/A 4.2 kB -
turbopack-0z..iibl.js gzip N/A 4.2 kB -
turbopack-1a..wxqm.js gzip N/A 4.2 kB -
turbopack-1k..iy2n.js gzip N/A 4.2 kB -
turbopack-1t..lhui.js gzip N/A 4.2 kB -
turbopack-1y..mujh.js gzip N/A 4.21 kB -
turbopack-28..frir.js gzip N/A 4.18 kB -
turbopack-29..fjt7.js gzip N/A 4.2 kB -
turbopack-2b..tnne.js gzip N/A 4.2 kB -
turbopack-2g..3kka.js gzip N/A 4.2 kB -
turbopack-2g..bysl.js gzip N/A 4.2 kB -
turbopack-2i..o69e.js gzip N/A 4.2 kB -
turbopack-30..bdvn.js gzip N/A 4.2 kB -
turbopack-3f..v-t6.js gzip N/A 4.2 kB -
Total 468 kB 468 kB ⚠️ +72 B

Server

Middleware
Canary PR Change
middleware-b..fest.js gzip 719 B 718 B
Total 719 B 718 B ✅ -1 B
Build Details
Build Manifests
Canary PR Change
_buildManifest.js gzip 433 B 434 B
Total 433 B 434 B ⚠️ +1 B

📦 Webpack

Client

Main Bundles
Canary PR Change
2258-HASH.js gzip 61.1 kB N/A -
2266-HASH.js gzip 4.69 kB N/A -
3317.HASH.js gzip 169 B N/A -
4866-HASH.js gzip 5.64 kB N/A -
9e302639-HASH.js gzip 62.7 kB N/A -
framework-HASH.js gzip 59.5 kB 59.5 kB
main-app-HASH.js gzip 256 B 253 B 🟢 3 B (-1%)
main-HASH.js gzip 39.9 kB 39.9 kB
webpack-HASH.js gzip 1.68 kB 1.68 kB
175fd0fd-HASH.js gzip N/A 62.7 kB -
2596-HASH.js gzip N/A 5.63 kB -
34-HASH.js gzip N/A 61 kB -
5691.HASH.js gzip N/A 169 B -
9156-HASH.js gzip N/A 4.68 kB -
Total 236 kB 236 kB ✅ -84 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 193 B 193 B
_error-HASH.js gzip 181 B 182 B
css-HASH.js gzip 334 B 332 B
dynamic-HASH.js gzip 1.79 kB 1.81 kB
edge-ssr-HASH.js gzip 255 B 255 B
head-HASH.js gzip 351 B 348 B
hooks-HASH.js gzip 385 B 384 B
image-HASH.js gzip 580 B 580 B
index-HASH.js gzip 257 B 259 B
link-HASH.js gzip 2.51 kB 2.52 kB
routerDirect..HASH.js gzip 318 B 319 B
script-HASH.js gzip 387 B 386 B
withRouter-HASH.js gzip 316 B 316 B
1afbb74e6ecf..834.css gzip 106 B 106 B
Total 7.97 kB 7.99 kB ⚠️ +19 B

Server

Edge SSR
Canary PR Change
edge-ssr.js gzip 126 kB 126 kB
page.js gzip 275 kB 270 kB 🟢 5.25 kB (-2%)
Total 401 kB 396 kB ✅ -5.43 kB
Middleware
Canary PR Change
middleware-b..fest.js gzip 616 B 614 B
middleware-r..fest.js gzip 155 B 155 B
middleware.js gzip 44.4 kB 44.8 kB
edge-runtime..pack.js gzip 842 B 842 B
Total 46 kB 46.4 kB ⚠️ +386 B
Build Details
Build Manifests
Canary PR Change
_buildManifest.js gzip 719 B 717 B
Total 719 B 717 B ✅ -2 B
Build Cache
Canary PR Change
0.pack gzip 4.45 MB 4.45 MB 🔴 +5.58 kB (+0%)
index.pack gzip 113 kB 114 kB
index.pack.old gzip 114 kB 116 kB 🔴 +1.56 kB (+1%)
Total 4.68 MB 4.68 MB ⚠️ +7.85 kB

🔄 Shared (bundler-independent)

Runtimes
Canary PR Change
app-page-exp...dev.js gzip 350 kB 350 kB
app-page-exp..prod.js gzip 194 kB 194 kB
app-page-tur...dev.js gzip 349 kB 349 kB
app-page-tur..prod.js gzip 194 kB 194 kB
app-page-tur...dev.js gzip 346 kB 346 kB
app-page-tur..prod.js gzip 192 kB 192 kB
app-page.run...dev.js gzip 346 kB 346 kB
app-page.run..prod.js gzip 192 kB 192 kB
app-route-ex...dev.js gzip 77.5 kB 77.5 kB
app-route-ex..prod.js gzip 52.9 kB 52.9 kB
app-route-tu...dev.js gzip 77.6 kB 77.6 kB
app-route-tu..prod.js gzip 52.9 kB 52.9 kB
app-route-tu...dev.js gzip 77.2 kB 77.2 kB
app-route-tu..prod.js gzip 52.7 kB 52.7 kB
app-route.ru...dev.js gzip 77.1 kB 77.1 kB
app-route.ru..prod.js gzip 52.7 kB 52.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 44.3 kB 44.3 kB
pages-api-tu..prod.js gzip 33.8 kB 33.8 kB
pages-api.ru...dev.js gzip 44.3 kB 44.3 kB
pages-api.ru..prod.js gzip 33.7 kB 33.7 kB
pages-turbo....dev.js gzip 53.7 kB 53.7 kB
pages-turbo...prod.js gzip 39.4 kB 39.4 kB
pages.runtim...dev.js gzip 53.6 kB 53.6 kB
pages.runtim..prod.js gzip 39.3 kB 39.3 kB
server.runti..prod.js gzip 63.2 kB 63.2 kB
use-cache-pr...dev.js gzip 69.7 kB 69.7 kB
use-cache-pr...dev.js gzip 69.7 kB 69.7 kB
use-cache-pr...dev.js gzip 68 kB 68 kB
use-cache-pr...dev.js gzip 68 kB 68 kB
Total 3.36 MB 3.36 MB ⚠️ +230 B
📝 Changed Files (8 files)

Files with changes:

  • app-page-exp..ntime.dev.js
  • app-page-exp..time.prod.js
  • app-page-tur..ntime.dev.js
  • app-page-tur..time.prod.js
  • app-page-tur..ntime.dev.js
  • app-page-tur..time.prod.js
  • app-page.runtime.dev.js
  • app-page.runtime.prod.js
View diffs
app-page-exp..ntime.dev.js
failed to diff
app-page-exp..time.prod.js

Diff too large to display

app-page-tur..ntime.dev.js
failed to diff
app-page-tur..time.prod.js

Diff too large to display

app-page-tur..ntime.dev.js
failed to diff
app-page-tur..time.prod.js

Diff too large to display

app-page.runtime.dev.js
failed to diff
app-page.runtime.prod.js

Diff too large to display

📎 Tarball URL
https://vercel-packages.vercel.app/next/commits/ff34f00b93bbb07619ccf26d182c3cedba28cf87/next

Commit: ff34f00

When a `"use cache"` propagated a dynamic cache life (`revalidate: 0` or
`expire` under 5 minutes) to a parent without an explicit `cacheLife`,
the resulting error pointed only at the outer cache invocation. With the
inner cache's call site missing, tracing which nested cache was
responsible meant reading through the outer's body — fine when it's
local code, much harder when the dynamism comes from a nested cache
buried in a third-party dependency.

This change attaches the inner invocation as `cause` of the error, so
the dev redbox and the build log show two stacks: the outer that threw,
and the inner that propagated the dynamic life.

The inner call site has to be captured eagerly while `cache()` is still
on the synchronous stack, because we only learn whether the inner
resolved dynamic asynchronously — after `collectResult` finishes and
`propagateCacheEntryMetadata` runs — and by then the inner's frames are
no longer on the JS stack. We only construct the eager `Error` when the
parent is itself a public `"use cache"` (the only case where this entry
could become a propagated origin), so top-level caches skip the
allocation. The eager `Error` is held on
`cacheContext.dynamicNestedCacheError`; once propagation knows the inner
resolved dynamic, it's copied onto the outer store's same-named field,
then carried through the outer's own `collectResult` into its RDC entry
— which the throw site finally reads back as `cause`. We keep the first
dynamic child — the immediate origin from the throwing cache's
perspective.

The two nested-dynamic cache error messages also get a small cleanup:
each used to write `"use cache"` two different ways within the same
sentence (bare and backticked); both now write it the same way.
@unstubbable unstubbable force-pushed the hl/nested-short-cache-life-stacks branch from 74aad9e to ff34f00 Compare May 9, 2026 12:07
@unstubbable unstubbable marked this pull request as ready for review May 9, 2026 12:49
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant