Link to the code that reproduces this issue
https://github.com/billyBrightwild/next-pending-prefetch-empty-head
To Reproduce
pnpm install
pnpm build && pnpm start # http://localhost:3030
pnpm exec playwright install chromium
pnpm test # 1 failed (the bug), 1 passed (control)
The failing test in e2e/repro.spec.ts widens the race deterministically: it holds every loading-boundary prefetch (the second-stage prefetch carrying Next-Router-State-Tree) for 1.5 s with page.route, while /_tree prefetches and real navigations pass through. Then:
- Load
/deal and wait until the viewport prefetches have started (hydrated).
- Click Open trip (
<Link href="/deal/trip">).
- Immediately click the Guests tab (
<Link href="/deal/trip/guests">) in a client-component tab strip rendered by the shared app/deal/layout.tsx, while the tab prefetches are still pending and the first navigation has not committed.
The control test performs the same two clicks after the prefetches settled and passes. Without the artificial delay the window is the prefetch's own round trip (20–100 ms): a hover or touch prefetch starts and the click lands before it completes, which is exactly what Playwright's click() (hover then click) and every touch tap do. We hit it in CI 3 nights in a row and 5 of 8 runs locally under CPU stress.
Route shape (a dynamic layout with generateMetadata, a nested dynamic layout with static metadata and a loading.tsx, and sibling tab pages without their own loading.tsx):
app/deal/layout.tsx headers(), generateMetadata, renders <TabStrip/> + {children}
app/deal/page.tsx <Link href="/deal/trip">Open trip</Link>
app/deal/trip/layout.tsx headers(), metadata = { title: "Your group trip" }
app/deal/trip/loading.tsx
app/deal/trip/page.tsx
app/deal/trip/guests/page.tsx force-dynamic, no loading.tsx
components/tab-strip.tsx "use client", <Link> per tab, default prefetch
Current vs. Expected behavior
Current. /deal/trip/guests renders, but document.title becomes "" and never recovers: the <title> element is removed. In our production app with the same route shape (Brightwild venue portal, next start, 2-vCPU GitHub runner, also locally under CPU stress) the same window additionally commits the URL with an empty content slot: no page, no loading.tsx skeleton, the layout's title kept, no console error, no recovery until reload. Fetching the same URL directly renders fine; the server log is clean. That variant is timing-dependent and is not made deterministic in the repro, but the mechanism below produces both.
Expected. The navigation shows loading.tsx, then the page, and the title becomes "Your group trip", exactly as when no prefetch is in flight.
Mechanism (traced with console instrumentation in dist/client/components/router-reducer/ppr-navigations.js; the same code is in 16.3.5 and in canary components/render-tree.ts):
createCacheNodeForSegment finds the target's segment-cache entries with status Pending and, instead of treating that as a cache miss, stores
cachedRsc = waitForSegmentCacheEntry(segmentEntry).then((entry) => entry !== null ? entry.rsc : null)
a plain promise, as the node's prefetchRsc, and the equivalent cachedHead promise as the node's final head (the pending head entry has isPartial: false, so the seedHead === null branch takes head = cachedHead instead of createDeferredRsc()). A sibling tab has no loading.tsx below the shared layout, so the server answers the prefetch with router state only; the entry is rejected and both promises resolve to null.
InnerLayoutRouter only null-guards its own DeferredRsc values (isDeferredRsc(rsc) → use(unresolvedThenable)). A plain promise resolving to null is rendered as a thenable child, becomes nothing, and React can commit the URL with an empty segment and no skeleton.
finishPendingCacheNode then skips the head because it is not deferred ("This is not a deferred RSC promise, nor is it empty, so it must have been populated by a different navigation. We must not overwrite it."), so the dynamic response's head is never applied; the <title> renders from the null promise and disappears.
Making the Pending branches behave as a miss (cachedRsc = null; isCachedRscPartial = true, and cachedHead = null; isCachedHeadPartial = true) removed both symptoms in our app (12/12 stressed runs vs 5/8 failures). prefetch={false} on the tab links avoids the path entirely. Neighbouring reports: #98305 (stuck transition after a completed RSC response), #86151.
Provide environment information
Operating System:
Platform: darwin
Arch: arm64
Version: Darwin Kernel Version 25.6.0
Available memory (MB): 49152
Available CPU cores: 18
Binaries:
Node: 22.22.3
npm: 10.9.8
pnpm: 11.9.0
Relevant Packages:
next: 16.2.11
react: 19.2.3
react-dom: 19.2.3
typescript: 5.8.3
Next.js Config:
output: N/A
Also observed on Ubuntu (GitHub Actions ubuntu-latest, Chromium via Playwright 1.61.1).
Which area(s) are affected? (Select all that apply)
Linking and Navigating, Loading UI and Streaming, Metadata
Which stage(s) are affected? (Select all that apply)
next build (local), next start (local)
Additional context
Not using cacheComponents, PPR, or staleTimes. The reproduction pins next@16.2.11; the relevant client code is unchanged in 16.3.5 (router-reducer/ppr-navigations.ts) and canary (components/render-tree.ts, case EntryStatus.Pending).
Link to the code that reproduces this issue
https://github.com/billyBrightwild/next-pending-prefetch-empty-head
To Reproduce
The failing test in
e2e/repro.spec.tswidens the race deterministically: it holds every loading-boundary prefetch (the second-stage prefetch carryingNext-Router-State-Tree) for 1.5 s withpage.route, while/_treeprefetches and real navigations pass through. Then:/dealand wait until the viewport prefetches have started (hydrated).<Link href="/deal/trip">).<Link href="/deal/trip/guests">) in a client-component tab strip rendered by the sharedapp/deal/layout.tsx, while the tab prefetches are still pending and the first navigation has not committed.The control test performs the same two clicks after the prefetches settled and passes. Without the artificial delay the window is the prefetch's own round trip (20–100 ms): a hover or touch prefetch starts and the click lands before it completes, which is exactly what Playwright's
click()(hover then click) and every touch tap do. We hit it in CI 3 nights in a row and 5 of 8 runs locally under CPU stress.Route shape (a dynamic layout with
generateMetadata, a nested dynamic layout with staticmetadataand aloading.tsx, and sibling tab pages without their ownloading.tsx):Current vs. Expected behavior
Current.
/deal/trip/guestsrenders, butdocument.titlebecomes""and never recovers: the<title>element is removed. In our production app with the same route shape (Brightwild venue portal,next start, 2-vCPU GitHub runner, also locally under CPU stress) the same window additionally commits the URL with an empty content slot: no page, noloading.tsxskeleton, the layout's title kept, no console error, no recovery until reload. Fetching the same URL directly renders fine; the server log is clean. That variant is timing-dependent and is not made deterministic in the repro, but the mechanism below produces both.Expected. The navigation shows
loading.tsx, then the page, and the title becomes "Your group trip", exactly as when no prefetch is in flight.Mechanism (traced with console instrumentation in
dist/client/components/router-reducer/ppr-navigations.js; the same code is in 16.3.5 and in canarycomponents/render-tree.ts):createCacheNodeForSegmentfinds the target's segment-cache entries with statusPendingand, instead of treating that as a cache miss, storesa plain promise, as the node's
prefetchRsc, and the equivalentcachedHeadpromise as the node's finalhead(the pending head entry hasisPartial: false, so theseedHead === nullbranch takeshead = cachedHeadinstead ofcreateDeferredRsc()). A sibling tab has noloading.tsxbelow the shared layout, so the server answers the prefetch with router state only; the entry is rejected and both promises resolve tonull.InnerLayoutRouteronly null-guards its ownDeferredRscvalues (isDeferredRsc(rsc)→use(unresolvedThenable)). A plain promise resolving tonullis rendered as a thenable child, becomes nothing, and React can commit the URL with an empty segment and no skeleton.finishPendingCacheNodethen skips the head because it is not deferred ("This is not a deferred RSC promise, nor is it empty, so it must have been populated by a different navigation. We must not overwrite it."), so the dynamic response's head is never applied; the<title>renders from thenullpromise and disappears.Making the
Pendingbranches behave as a miss (cachedRsc = null; isCachedRscPartial = true, andcachedHead = null; isCachedHeadPartial = true) removed both symptoms in our app (12/12 stressed runs vs 5/8 failures).prefetch={false}on the tab links avoids the path entirely. Neighbouring reports: #98305 (stuck transition after a completed RSC response), #86151.Provide environment information
Also observed on Ubuntu (GitHub Actions
ubuntu-latest, Chromium via Playwright 1.61.1).Which area(s) are affected? (Select all that apply)
Linking and Navigating, Loading UI and Streaming, Metadata
Which stage(s) are affected? (Select all that apply)
next build (local), next start (local)
Additional context
Not using
cacheComponents, PPR, orstaleTimes. The reproduction pinsnext@16.2.11; the relevant client code is unchanged in 16.3.5 (router-reducer/ppr-navigations.ts) and canary (components/render-tree.ts,case EntryStatus.Pending).