Skip to content

App Router: a <Link> clicked while its prefetch is in flight commits with no <title> (and can commit an empty segment) — Pending segment-cache entry is handed to React as a plain promise #98684

Description

@billyBrightwild

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:

  1. Load /deal and wait until the viewport prefetches have started (hydrated).
  2. Click Open trip (<Link href="/deal/trip">).
  3. 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).

Activity

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    Linking and NavigatingRelated to Next.js linking (e.g., <Link>) and navigation.Loading UI and StreamingRelated to loading UI (loading.tsx) and streaming.MetadataRelated to Next.js' Metadata API.

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions