App Router: `"use cache"` build-time, private, and route-handler revalidate broken
#1 453 ouverte le 22 mai 2026
Métriques du dépôt
- Stars
- (8 120 stars)
- Métriques de merge PR
- (Merge moyen 1j 1h) (462 PRs mergées en 30 j)
Description
This issue was created by an agent analysing CI failures from the Next.js Deploy Suite (vinext
mainvs Next.jsv16.2.6, 2026-05-22).
Problem
Several "use cache" behaviors are broken: (1) Functions reached via prerender / metadata route handler / inline server action are evaluated at runtime instead of build time, so sitemap/robots/manifest emit sentinel=runtime instead of sentinel=buildtime. (2) "use cache: private" does not expose cookies/searchParams to the cached function. (3) Prerendered route handlers using 'use cache' cannot be revalidated via revalidatePath/revalidateTag. (4) A server action that depends on a nested cached function passed as a prop never produces a clickable hydrated button.
- <loc>https://acme.com?sentinel=buildtime</loc>
+ <loc>https://acme.com?sentinel=runtime</loc>
use cache: private - #test-cookie / #search-param selectors remain hidden
Expected: not "2026-05-22T10:49:42.408Z" // route handler revalidate did not change timestamp
Estimated Impact
~9 test failures across the deploy suite.
Affected Test Suites
test/e2e/app-dir/use-cache-metadata-route-handler/use-cache-metadata-route-handler.test.ts(4 failures)test/e2e/app-dir/use-cache-private/use-cache-private.test.ts(2 failures)test/e2e/app-dir/cache-components/cache-components.server-action.test.tstest/e2e/app-dir/use-cache-route-handler-only/use-cache-route-handler-only.test.tstest/e2e/app-dir/use-cache-with-server-function-props/use-cache-with-server-function-props.test.ts
Recommendation
-
Reproduce first in vinext's own test suite. Cover the four cases independently: (a)
"use cache"in a metadata route handler, (b)"use cache: private"reading cookies, (c) revalidating a'use cache'route handler, (d) a nested cached function passed as a prop into a server action. -
Study Next.js
"use cache"evaluation. Search.nextjs-ref/packages/next/src/server/use-cache/and.nextjs-ref/packages/next/src/build/for buildtime evaluation, private inputs, route-handler revalidation, and nested action serialization. -
Wire
"use cache"into the prerender pipeline. When prerendering metadata routes, sitemaps, robots, and inline server actions, the cache function should be evaluated against the prerender execution context so it seesbuildtimesentinels and produces stable values. -
Thread cookies/searchParams into private cache scopes.
"use cache: private"must bind to the request scope socookies()/searchParamsread at request time. -
Make route-handler revalidation trigger invalidation.
revalidatePath/revalidateTagmust evict cached route-handler responses just like cached page responses.