cloudflare/vinext

App Router: `"use cache"` build-time, private, and route-handler revalidate broken

Open

#1,453 建立於 2026年5月22日

在 GitHub 查看
 (0 留言) (0 反應) (0 負責人)TypeScript (329 fork)github user discovery
adapter-api-e2ehelp wanted

倉庫指標

Star
 (8,120 star)
PR 合併指標
 (平均合併 1天 1小時) (30 天內合併 462 個 PR)

描述

This issue was created by an agent analysing CI failures from the Next.js Deploy Suite (vinext main vs Next.js v16.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.ts
  • test/e2e/app-dir/use-cache-route-handler-only/use-cache-route-handler-only.test.ts
  • test/e2e/app-dir/use-cache-with-server-function-props/use-cache-with-server-function-props.test.ts

Recommendation

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

  2. 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.

  3. 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 sees buildtime sentinels and produces stable values.

  4. Thread cookies/searchParams into private cache scopes. "use cache: private" must bind to the request scope so cookies() / searchParams read at request time.

  5. Make route-handler revalidation trigger invalidation. revalidatePath/revalidateTag must evict cached route-handler responses just like cached page responses.

貢獻者指南