next.js
bedf3665 - [refactor] Replace runtime prefetch sentinel transform stream (#90160)

Commit
2 days ago
[refactor] Replace runtime prefetch sentinel transform stream (#90160) Runtime prefetch responses previously encoded `isPartial` and `staleTime` using a sentinel-and-replace pattern: a random number was embedded in the RSC payload during prerendering, then a TransformStream scanned the prelude stream to find and replace it with the actual values. This was fragile because it relied on matching a specific byte sequence in a chunked stream that could be split at arbitrary boundaries. This replaces that mechanism with two simpler approaches: - **isPartial**: A single byte prepended to the response stream (`#` for complete, `~` for partial). - **staleTime**: An `AsyncIterable<number>` in the Flight payload that yields updated stale time values as the prerender store changes. This ensures the latest value is always serialized in the stream, even when sync IO aborts the prerender before the abort callback runs. The stale time tracking logic is extracted into a new `stale-time.ts` module with `StaleTimeIterable`, `trackStaleTime`, and `finishStaleTimeTracking`. On the client, dynamic runtime prefetch responses (detected via the absence of `NEXT_IS_PRERENDER_HEADER`) have the byte stripped before Flight decoding, and the stale time is read by iterating the async iterable. Static responses served from cache are handled unchanged.
Author
Parents
Loading