UNPKG

next

Version:

The React Framework

168 lines (167 loc) • 10.6 kB
/** * App Router types - Client-safe types for the Next.js App Router * * This file contains type definitions that can be safely imported * by both client-side and server-side code without circular dependencies. */ export var PrefetchHint = /*#__PURE__*/ function(PrefetchHint) { // NOTE: The 0b00001 bit was previously HasRuntimePrefetch (prefetch: // 'allow-runtime'). Partial Prefetching allows using runtime requests // for every segment, so the bit was removed. Do not reuse it without // considering caches populated by older builds. // This segment or one of its descendants opts into Partial Prefetching, i.e. // uses the two-phase (Shell then Speculative) prefetch flow. Set when // `prefetch` is 'partial' (including the default implied by the global // `partialPrefetching` config). Propagates upward so the root segment // reflects the entire subtree. // // Partial Prefetching routes may use runtime requests for both shells // and prefetches. They *may* be optimized to a use a static request // if no runtime data was accessed during the prerender. // However, If the route has `ensureStatic` configured to "shell", "prefetch", // or "navigation", we *must* use static requests for the shell (and possibly the // prefetch). // Both of these cases are signalled to the scheduler via the // `ShouldAttemptStatic{Shell,Prefetch}` hints and the `needsRuntimeRequest` // promise. PrefetchHint[PrefetchHint["SubtreeHasPartialPrefetching"] = 2] = "SubtreeHasPartialPrefetching"; // This segment itself has a loading.tsx boundary. PrefetchHint[PrefetchHint["SegmentHasLoadingBoundary"] = 4] = "SegmentHasLoadingBoundary"; // A descendant segment (but not this one) has a loading.tsx boundary. // Propagates upward so the root reflects the entire subtree. PrefetchHint[PrefetchHint["SubtreeHasLoadingBoundary"] = 8] = "SubtreeHasLoadingBoundary"; // This segment is at or above the application's root layout — the root layout // segment itself and all of its ancestors. A dynamic param in one of these // segments is a "root param". PrefetchHint[PrefetchHint["IsRootLayoutOrAbove"] = 16] = "IsRootLayoutOrAbove"; // This segment's response includes its parent's data inlined into it. // Set at build time by the segment size measurement pass. PrefetchHint[PrefetchHint["ParentInlinedIntoSelf"] = 32] = "ParentInlinedIntoSelf"; // This segment's data is inlined into one of its children — don't fetch // it separately. Set at build time by the segment size measurement pass. PrefetchHint[PrefetchHint["InlinedIntoChild"] = 64] = "InlinedIntoChild"; // On a __PAGE__: this page's response includes the head (metadata/viewport) // in its transport data (PartialTransportData's `h`). PrefetchHint[PrefetchHint["HeadInlinedIntoSelf"] = 128] = "HeadInlinedIntoSelf"; // On the root hint node: the head was NOT inlined into any page — fetch // it separately. Absence of this bit means the head is bundled into a page. PrefetchHint[PrefetchHint["HeadOutlined"] = 256] = "HeadOutlined"; // The inlining hints in this tree may be stale because the tree was // generated before collectPrefetchHints ran (e.g. the initial RSC payload // for a fully static page at build time). When writing this tree into the // cache, the route entry should be immediately expired so it gets // re-fetched with correct hints. Only set during build-time prerendering, // never at runtime. PrefetchHint[PrefetchHint["InliningHintsStale"] = 512] = "InliningHintsStale"; // This segment has prefetch = 'force-disabled'. The opt-out is passive // and applies to this segment only: it never INITIATES a prefetch — no // static data is emitted or fetched, and it's never the reason a runtime // prefetch spawns — but it may ride along in a runtime response issued on // another segment's behalf. Descendants prefetch normally. // // TODO: Also set as an internal fallback when the prefetch hints manifest // is unavailable (see #91407 mitigations), which only means "no static // prefetch data exists" — not a user opt-out. Split the fallback into its // own bit so the two intents can diverge. PrefetchHint[PrefetchHint["PrefetchDisabled"] = 1024] = "PrefetchDisabled"; // NOTE: The 0b100000000000 bit was previously SubtreeHasRuntimePrefetch. // Partial Prefetching now implies runtime completeness for every segment // (see SubtreeHasPartialPrefetching), so the bit was removed. Do not reuse // it without considering caches populated by older builds. // NOTE: The 0b1000000000000 bit was previously SubtreeHasEagerPrefetch // (prefetch: 'unstable_eager', plus every segment that did not opt into // Partial Prefetching). After `unstable_eager` was removed, it's no longer needed. // This segment or one of its descendants exports `instant = false`, // explicitly opting out of Partial Prefetching. Propagates upward so the root // reflects the entire subtree. Used only to suppress the dev-time // `<Link prefetch={true}>` warning — unlike PrefetchDisabled, it has no effect // on the actual prefetch behavior. PrefetchHint[PrefetchHint["SubtreeHasInstantFalse"] = 8192] = "SubtreeHasInstantFalse"; // The client should attempt a static prefetch for this route: the // build-time prerender did not access any runtime data (cookies, headers, // searchParams, ...), so a static prefetch is expected to be as complete // as a runtime one. A fallback-param access only unsets the bit when the // route can never be upgraded from a fallback to a concrete prerender — // on an upgradeable route, ISR later produces the concrete prerender a // static attempt would hit (until then, the static responses' own // signal reports the insufficiency per response). Purely advisory, and // both error directions are safe: if set when a runtime request is // actually needed, that same response-level signal (the load-bearing // `needsRuntimeRequest` promise combined with each segment's `isPartial`) // directs the client to follow up — the cost is a wasted static attempt. // If unset when static would have sufficed, the client goes straight to a // runtime prefetch, which is a superset of the static response — the cost // is only reduced cacheability. Like the other bits, this one is computed // once per build and stays constant for the build's lifetime; it rides // the prefetch-hints manifest into every response that carries hints — // `/_tree` prefetch responses and the FlightRouterState of dynamic // navigations alike. (Routes missing from the manifest — see the #91407 // fallbacks — simply never carry it.) Set on every node of the tree, but // does not propagate. PrefetchHint[PrefetchHint["ShouldAttemptStaticShell"] = 16384] = "ShouldAttemptStaticShell"; PrefetchHint[PrefetchHint["ShouldAttemptStaticPrefetch"] = 32768] = "ShouldAttemptStaticPrefetch"; // This dynamic segment only accepts build-time parameter values. Kept on // the affected node, without propagating or copying it to other segments. // Until the client knows the allowed values, any such node prevents route // prediction, even when the route's components never read the parameter. PrefetchHint[PrefetchHint["IsClosedParam"] = 65536] = "IsClosedParam"; // A descendant segment (but not this one) has a closed parameter. Propagates // upward so route prediction can check the root instead of walking the tree. PrefetchHint[PrefetchHint["SubtreeHasClosedParams"] = 131072] = "SubtreeHasClosedParams"; return PrefetchHint; }({}); /** * Bitmask for checking whether a segment's static prefetch is skipped — i.e. * the server emits no static data for it (its node in a segment response * carries identity only, and it participates in a bundle only as a * pass-through) and the client never issues a static request for it. * * Static prefetching is disabled ONLY by `prefetch: 'force-disabled'` * (PrefetchDisabled). Notably, Partial Prefetching segments DO have static * data even though they can use runtime requests: the server emits it * unconditionally — it can't be gated on the ShouldAttemptStatic{Shell,Prefetch} * hints, because which segments carry static data must be deterministic * from build-time config. A runtime request may still be needed for the * segment, but the scheduler may attempt a static prefetch first (per the * ShouldAttemptStatic{Shell,Prefetch} hints) and skip the runtime request if the * static response proves sufficient. * * Usage: `(hints & StaticPrefetchDisabled) !== 0` */ export const StaticPrefetchDisabled = 1024; export const StaticAttemptHints = 16384 | 32768; /** * The subset of PrefetchHint bits that propagate upward from a child segment to * its ancestors (as opposed to segment-local bits like SegmentHasLoadingBoundary * or IsRootLayoutOrAbove). Used to clear stale propagated bits before re-deriving them * from a node's children. */ export const SubtreePrefetchHints = 2 | 8 | 8192 | 131072; /** * Folds a child segment's prefetch hints into its parent's, propagating the * "subtree" flags. A child's segment-local flag (e.g. it has a loading * boundary) becomes the corresponding "subtree" flag on the parent, so the * root segment ends up reflecting the entire subtree. * * Used wherever a route tree is assembled bottom-up: on the server when building * a transport tree (createTransportTreeFromLoaderTree) and on the client when * overlaying a navigation response onto the existing tree * (createNavigationSeed). Keep these in sync by routing both through * this helper. */ export function propagateSubtreeBits(parentHints, childHints) { if (childHints & 2) { parentHints |= 2; } // A child with a loading boundary (directly, or anywhere in its subtree) makes // this a SubtreeHasLoadingBoundary on the parent. if (childHints & (4 | 8)) { parentHints |= 8; } // And for `instant = false`. The bit is set directly on each opted-out // segment, so there's no separate segment-local flag — propagate it as-is. if (childHints & 8192) { parentHints |= 8192; } if (childHints & (65536 | 131072)) { parentHints |= 131072; } return parentHints; } //# sourceMappingURL=app-router-types.js.map