Unverified Commit 19d1fc52 authored by Andrew Clark's avatar Andrew Clark Committed by GitHub

Unify how a response's shell and full payloads are written (#96878)

A response may contain two payloads: the full response, plus a shell
stage that the client obtains by decoding the same bytes again,
truncated at the shell byte offset. Each flow had its own copy of the
logic that decides which payload fulfills the pending entries and what
fetch strategy each write records. Those copies are replaced by a single
function, writeResponsePayloadsIntoCache. The embedded runtime prefetch
stream, which previously ignored the byte offset entirely, now goes
through it too.

When a shell request receives more than it asked for, the extra content
is at least as complete as what the corresponding non-shell request
would have returned, so that's the strategy the write records: PPR for a
StaticShell request, PPRRuntime for a RuntimeShell request. Previously
some of these writes under-recorded, causing the scheduler to issue
runtime requests for content it already had. A rejected
needsRuntimeRequest row now also reads conservatively (as true) on the
client, matching how the server reads the same flag.

The second commit fixes an oversight where a static prefetch attempt was
mistakenly skipped: when the scheduler found a cached entry that was
only a shell, it deopted straight to a runtime request even though the
full static response contains more and the segment's hint says a static
attempt is worthwhile. A shell entry with the hint now takes the normal
static revalidation path first, and the response's own signals decide
whether to escalate afterward.
parent 12b802b2
...@@ -785,7 +785,10 @@ export function matchKnownRoute( ...@@ -785,7 +785,10 @@ export function matchKnownRoute(
// This shouldn't be reachable for a valid route tree. // This shouldn't be reachable for a valid route tree.
return null return null
} }
const reifiedMetadata = createMetadataRouteTree(metadataVaryPath) const reifiedMetadata = createMetadataRouteTree(
metadataVaryPath,
reifiedTree.prefetchHints
)
// Create a synthetic (predicted) entry and store it as the new pattern. // Create a synthetic (predicted) entry and store it as the new pattern.
// //
......
...@@ -38,14 +38,23 @@ export const enum FetchStrategy { ...@@ -38,14 +38,23 @@ export const enum FetchStrategy {
// canNewFetchStrategyProvideMoreContent in cache.ts for what each tier can // canNewFetchStrategyProvideMoreContent in cache.ts for what each tier can
// contain relative to the others. // contain relative to the others.
// //
// Full and LoadingBoundary belong to the non-Partial-Prefetching regime:
// they're only relevant in modes where the staging concepts (shell tiers,
// runtime prefetches) don't apply. They sit on this single ordered ladder
// as an accepted convenience, because cross-regime comparisons exist
// (e.g. canNewFetchStrategyProvideMoreContent).
//
// These numeric values are client-internal and never cross the wire — the // These numeric values are client-internal and never cross the wire — the
// `next-router-prefetch` request header values are mapped explicitly in // `next-router-prefetch` request header values are mapped explicitly in
// fetchSegmentPrefetchesUsingRuntimeRequest (cache.ts) — so the members can // fetchSegmentPrefetchesUsingRuntimeRequest (cache.ts) — so the members can
// be renumbered freely as long as the relative order is preserved. // be renumbered freely as long as the relative order is preserved.
LoadingBoundary = 0, LoadingBoundary = 0,
// The App Shell variant extracted from a static per-segment prefetch // The shell-stage variant extracted from a static per-segment prefetch
// response: every segment's param-dependent content is reduced to pending // response: every segment's param-dependent content is reduced to pending
// references that render as the param fallback. Less complete than // references that render as the param fallback, keyed at the shell vary
// paths (only root params kept concrete). The Shell PHASE that issues
// these requests targets the conceptual App Shell; the strategy itself is
// just this mechanical truncation and keying. Less complete than
// RuntimeShell — a static response can't include content that depends on // RuntimeShell — a static response can't include content that depends on
// session data (cookies, headers) — and less complete than PPR at concrete // session data (cookies, headers) — and less complete than PPR at concrete
// paths, which includes prerendered param-dependent content. // paths, which includes prerendered param-dependent content.
......
...@@ -207,8 +207,10 @@ export async function collectSegmentData( ...@@ -207,8 +207,10 @@ export async function collectSegmentData(
// row reads as `false`: a successful render always settles the flag // row reads as `false`: a successful render always settles the flag
// (prerender completion resolves `false`), so a pending row can only // (prerender completion resolves `false`), so a pending row can only
// appear in an aborted render's buffer, where it means no access was // appear in an aborted render's buffer, where it means no access was
// recorded before the abort. // recorded before the abort. A rejected row reads as `true`,
runtimeDataAccessed = readFulfilledValue(pagePayload.u, false) // conservatively — an abort errors rows that were still pending when
// it happened.
runtimeDataAccessed = readFulfilledValue(pagePayload.u, false, true)
} }
} catch {} } catch {}
......
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