next.js
12b802b2 - Convert per-segment prefetches to NavigationFlightResponse format (#96877)

Commit
37 days ago
Convert per-segment prefetches to NavigationFlightResponse format (#96877) This is the last of the changes to convert all RSC requests to a single unified response type, NavigationFlightResponse. The old format was a positional array whose ordering had to be kept in sync by hand between the server and the client. The new format is the same root-anchored tree used by every other response, so the dedicated client write path for per-segment responses is deleted and these responses go through the shared one. A few functions are renamed as their roles change: convertServerPatchToFullTree becomes createNavigationSeed (it now also accepts trees with no base to overlay), fetchSegmentsOnCacheMiss becomes fetchSegmentPrefetchesUsingStaticRequest (the counterpart of fetchSegmentPrefetchesUsingRuntimeRequest), and writeSeedDataIntoCache becomes writeTreeDataIntoCache (seed data no longer exists as a concept). During the unification, a few inconsistencies and oversights were caught and fixed: response data with no matching pending entry is written as a detached entry instead of dropped, and a response's byte size is spread across the entries it actually fulfilled rather than the old chain-based count. The fallback retry loop also marks itself pending before the first cache write instead of after, closing a window where the scheduler could spawn a duplicate revalidation. The second commit unifies cache keying for prefetched segments. There were two implementations of the logic that decides which cache key a prefetched segment is written to, one for per-segment responses and one for responses produced by a live render. Now there's one: if the server reported which params the segment depends on, key the entry using those; otherwise fall back to the keying implied by how the payload was fetched. A segment is only treated as param-independent when the server says so. Two precedence fixes were needed to merge them, and a few other inconsistencies found during the unification are fixed along the way; see the commit message for details.
Author
Parents
Loading