vercel / vercel/next.js

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

Open
#98,684 0 comments 0 reactions 0 assignees View on GitHub

Nobody has claimed this yet.

Linking and Navigating Loading UI and Streaming Metadata
Dominant language
JavaScript
Stars
142k
Forks
32.4k
Avg merge
2d 14h
Merged PRs (30d)
351

Description

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

Contributor guide

Open the contributing guide

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

Research direction

Run the reproduction with pnpm test, starting with the failing e2e/repro.spec.ts scenario. Read the Pending handling in components/render-tree.ts and router-reducer/ppr-navigations.ts, then trace the segment-cache entry and head values through navigation. Done means the race shows loading.tsx, renders the page, preserves the “Your group trip” title, and the regression test passes.

Written by the indexing model from the issue text.

Assessment

Tech stack
javascript, nextjs, playwright, react
Domain
frontend, testing, web-dev
Issue type
Bug
Difficulty
4/5
Estimated time
3-5 days
Activity status
Active
Clarity
Clearly specified
Newbie friendliness
48/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.