Unverified Commit 93a720f1 authored by Andrew Clark's avatar Andrew Clark Committed by GitHub

[Prefetching] Move resource hints to tree prefetch (#72367)

Based on:
- #72348

---


When prefetching a segment, the response currently includes all the side
effects (e.g. resource hints and console.logs) for the entire page, not
just the segment being requested. This is mostly the result of
implementation limitations, since React does not currently give us a
good way to extract side effects from an existing Flight response. We
cheat by decoding the original stream inside a new Flight render, which
has the effect of transferring all the side effects from the original
stream onto the new one.

This is mostly fine, except 1) every segment contains the entire page's
resource hints, and 2) we have to decode the original stream once per
segment.

But since all route prefetches must start with a prefetch of the route
tree metadata, we can instead put the hints in that response only. Not
the segment prefetches. That way we only have to decode the original
stream once.

This saves CPU cycles and should result in fewer bytes over the wire,
since we'll only load the resource hints once per page.
parent 0ae76cbc
......@@ -3880,6 +3880,7 @@ async function collectSegmentData(
return
}
const routeTree: FlightRouterState = flightDataPaths[0][0]
const seedData: CacheNodeSeedData = flightDataPaths[0][1]
// Manifest passed to the Flight client for reading the full-page Flight
// stream. Based off similar code in use-cache-wrapper.ts.
......@@ -3898,6 +3899,7 @@ async function collectSegmentData(
const staleTime = prerenderStore.stale
return await ComponentMod.collectSegmentData(
routeTree,
seedData,
fullPageDataBuffer,
staleTime,
clientReferenceManifest.clientModules as ManifestNode,
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment