Skip to content

fix(instrumentation): load segmentData from disk in registerInitialCache - #237

Merged
AyronK merged 1 commit into
fortedigital:masterfrom
gergokee:fix/segment-data-warmup-nextjs-16
Aug 12, 2026
Merged

fix(instrumentation): load segmentData from disk in registerInitialCache#237
AyronK merged 1 commit into
fortedigital:masterfrom
gergokee:fix/segment-data-warmup-nextjs-16

Conversation

@gergokee

Copy link
Copy Markdown
Contributor

In Next.js 16.3.0 the segment prefetch protocol changed: the browser sends next-router-segment-prefetch: /_tree requests expecting a compact TreePrefetch payload. When segmentData is missing from the cached ISR entry the server falls back to returning the full-page RSC (InitialRSCPayload), which the Next.js 16 client cannot parse as a route-tree response and retries indefinitely — causing a flood of RSC fetch calls for the entire cache TTL after every deploy.

Each pre-rendered App Router page now ships alongside a <route>.segments/ directory whose files contain the per-segment RSC payloads (/_tree, /_full, /$locale, …). The route's .meta file lists them in a segmentPaths array.

This commit:

  • Adds segmentPaths?: string[] to the NextRouteMetadata type so the field is recognised when the .meta file is parsed.
  • After reading the .meta file, reads every segment file listed in meta.segmentPaths from the .segments/ directory and builds a Map<string, Buffer> that is stored as segmentData on the cached value. Files that are absent are skipped silently so the function remains backwards-compatible with Next.js 15 builds (which produce no .segments directories).

In Next.js 16.3.0 the segment prefetch protocol changed: the browser
sends `next-router-segment-prefetch: /_tree` requests expecting a
compact TreePrefetch payload. When segmentData is missing from the
cached ISR entry the server falls back to returning the full-page RSC
(InitialRSCPayload), which the Next.js 16 client cannot parse as a
route-tree response and retries indefinitely — causing a flood of
RSC fetch calls for the entire cache TTL after every deploy.

Each pre-rendered App Router page now ships alongside a
`<route>.segments/` directory whose files contain the per-segment RSC
payloads (/_tree, /_full, /$locale, …). The route's .meta file
lists them in a `segmentPaths` array.

This commit:
- Adds `segmentPaths?: string[]` to the `NextRouteMetadata` type so
  the field is recognised when the .meta file is parsed.
- After reading the .meta file, reads every segment file listed in
  `meta.segmentPaths` from the `.segments/` directory and builds a
  `Map<string, Buffer>` that is stored as `segmentData` on the cached
  value.  Files that are absent are skipped silently so the function
  remains backwards-compatible with Next.js 15 builds (which produce no
  .segments directories).
@AyronK

AyronK commented Aug 12, 2026

Copy link
Copy Markdown
Collaborator

Thanks @gergokee, I'll draft a patch today.

@AyronK
AyronK merged commit 8861a12 into fortedigital:master Aug 12, 2026
2 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants