fix(instrumentation): load segmentData from disk in registerInitialCache - #237
Merged
AyronK merged 1 commit intoAug 12, 2026
Merged
Conversation
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
self-requested a review
August 12, 2026 10:11
AyronK
approved these changes
Aug 12, 2026
Collaborator
|
Thanks @gergokee, I'll draft a patch today. |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
In Next.js 16.3.0 the segment prefetch protocol changed: the browser sends
next-router-segment-prefetch: /_treerequests 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 asegmentPathsarray.This commit:
segmentPaths?: string[]to theNextRouteMetadatatype so the field is recognised when the .meta file is parsed.meta.segmentPathsfrom the.segments/directory and builds aMap<string, Buffer>that is stored assegmentDataon 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).