mirror of
https://github.com/hanzoai/next.js.git
synced 2026-09-24 17:00:51 +00:00
With `partialPrefetching` enabled, navigating back to a page that was
first loaded as a full HTML document served stale dynamic content. Its
`connection()`-gated output kept showing the value from the original
document load instead of being re-run per request, and the `<Link
prefetch={true}>` navigation issued no server request at all. A page
first reached through a prefetch behaved correctly, so the problem only
surfaced after an initial HTML load.
The cause was a missing prefetch hint on the route tree that the client
caches from that initial HTML render. The app-page build template
assembles the route module's `renderOpts` directly from `nextConfig`,
and that field list carried `cacheComponents` and the `experimental`
block but left out `partialPrefetching`. So
`renderOpts.partialPrefetching` was `undefined` for every runtime render
even with the flag on; only the build-time prerender and per-segment
prefetch artifacts, produced through the export worker, had the correct
value. As a result the route tree computed at runtime and inlined into
the initial HTML lacked the `SubtreeHasPartialPrefetching` hint and
picked up `SubtreeHasEagerPrefetch` instead. When that tree was later
reused for a `prefetch={true}` navigation, the client never downgraded
the full prefetch to a partial one, so it promoted the fully resolved
hydration entry out of the bfcache into a non-partial segment and served
it stale.
The fix passes `nextConfig.partialPrefetching` through the template's
`renderOpts` (kept raw so `'unstable_eager'` survives), so runtime
renders emit the same hint as the build artifacts and the existing
client-side downgrade handles the rest. A regression test navigates back
to a page after its initial HTML load and asserts, via the router `act`
helper, that the navigation re-fetches the dynamic content instead of
serving it stale.
17 lines
326 B
TypeScript
17 lines
326 B
TypeScript
import Link from 'next/link'
|
|
import { ReactNode } from 'react'
|
|
export default function Root({ children }: { children: ReactNode }) {
|
|
return (
|
|
<html>
|
|
<body>
|
|
<nav>
|
|
<Link href="/" prefetch={false}>
|
|
Home
|
|
</Link>
|
|
</nav>
|
|
{children}
|
|
</body>
|
|
</html>
|
|
)
|
|
}
|