Skip to content

Commit 1d285ae

Browse files
authored
[metadata] Align prefetch head type with head (vercel#74161)
1 parent eff54a3 commit 1d285ae

File tree

3 files changed

+14
-11
lines changed

3 files changed

+14
-11
lines changed

packages/next/src/client/components/router-reducer/ppr-navigations.ts

Lines changed: 10 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -71,7 +71,7 @@ export function updateCacheNodeOnNavigation(
7171
oldRouterState: FlightRouterState,
7272
newRouterState: FlightRouterState,
7373
prefetchData: CacheNodeSeedData | null,
74-
prefetchHead: HeadData,
74+
prefetchHead: HeadData | null,
7575
isPrefetchHeadPartial: boolean
7676
): Task | null {
7777
// Diff the old and new trees to reuse the shared layouts.
@@ -286,7 +286,7 @@ export function updateCacheNodeOnNavigation(
286286
function createCacheNodeOnNavigation(
287287
routerState: FlightRouterState,
288288
prefetchData: CacheNodeSeedData | null,
289-
possiblyPartialPrefetchHead: HeadData,
289+
possiblyPartialPrefetchHead: HeadData | null,
290290
isPrefetchHeadPartial: boolean
291291
): Task {
292292
// Same traversal as updateCacheNodeNavigation, but we switch to this path
@@ -387,7 +387,10 @@ function createCacheNodeOnNavigation(
387387
// `prefetchRsc` field.
388388
rsc,
389389
prefetchRsc: null,
390-
head: isLeafSegment ? possiblyPartialPrefetchHead : [null, null],
390+
head: (isLeafSegment ? possiblyPartialPrefetchHead : null) ?? [
391+
null,
392+
null,
393+
],
391394
prefetchHead: null,
392395
loading,
393396
parallelRoutes: cacheNodeChildren,
@@ -422,7 +425,7 @@ function patchRouterStateWithNewChildren(
422425
function spawnPendingTask(
423426
routerState: FlightRouterState,
424427
prefetchData: CacheNodeSeedData | null,
425-
prefetchHead: React.ReactNode | null,
428+
prefetchHead: HeadData | null,
426429
isPrefetchHeadPartial: boolean
427430
): Task {
428431
// Create a task that will later be fulfilled by data from the server.
@@ -645,7 +648,7 @@ function finishTaskUsingDynamicDataPayload(
645648
function createPendingCacheNode(
646649
routerState: FlightRouterState,
647650
prefetchData: CacheNodeSeedData | null,
648-
prefetchHead: React.ReactNode | null,
651+
prefetchHead: HeadData | null,
649652
isPrefetchHeadPartial: boolean
650653
): ReadyCacheNode {
651654
const routerStateChildren = routerState[1]
@@ -685,7 +688,7 @@ function createPendingCacheNode(
685688
parallelRoutes: parallelRoutes,
686689

687690
prefetchRsc: maybePrefetchRsc !== undefined ? maybePrefetchRsc : null,
688-
prefetchHead: isLeafSegment ? prefetchHead : null,
691+
prefetchHead: isLeafSegment ? prefetchHead : [null, null],
689692

690693
// TODO: Technically, a loading boundary could contain dynamic data. We must
691694
// have separate `loading` and `prefetchLoading` fields to handle this, like
@@ -940,7 +943,7 @@ export function updateCacheNodeOnPopstateRestoration(
940943
rsc,
941944
head: oldCacheNode.head,
942945

943-
prefetchHead: shouldUsePrefetch ? oldCacheNode.prefetchHead : null,
946+
prefetchHead: shouldUsePrefetch ? oldCacheNode.prefetchHead : [null, null],
944947
prefetchRsc: shouldUsePrefetch ? oldCacheNode.prefetchRsc : null,
945948
loading: oldCacheNode.loading,
946949

packages/next/src/client/components/segment-cache/navigation.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -126,7 +126,7 @@ function navigateUsingPrefetchedRouteTree(
126126
currentFlightRouterState: FlightRouterState,
127127
prefetchFlightRouterState: FlightRouterState,
128128
prefetchSeedData: CacheNodeSeedData | null,
129-
prefetchHead: HeadData,
129+
prefetchHead: HeadData | null,
130130
isPrefetchHeadPartial: boolean,
131131
canonicalUrl: string
132132
): SuccessfulNavigationResult | NoOpNavigationResult {
@@ -302,7 +302,7 @@ async function navigateDynamicallyWithNoPrefetch(
302302
// In our simulated prefetch payload, we pretend that there's no seed data
303303
// nor a prefetch head.
304304
const prefetchSeedData = null
305-
const prefetchHead: [null, null] = [null, null]
305+
const prefetchHead = null
306306
const isPrefetchHeadPartial = true
307307

308308
const canonicalUrl = createCanonicalUrl(

packages/next/src/shared/lib/app-router-context.shared-runtime.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -56,7 +56,7 @@ export type LazyCacheNode = {
5656
*/
5757
lazyData: Promise<FetchServerResponseResult> | null
5858

59-
prefetchHead: React.ReactNode
59+
prefetchHead: HeadData | null
6060

6161
head: HeadData
6262

@@ -99,7 +99,7 @@ export type ReadyCacheNode = {
9999
* There should never be a lazy data request in this case.
100100
*/
101101
lazyData: null
102-
prefetchHead: React.ReactNode
102+
prefetchHead: HeadData | null
103103

104104
head: HeadData
105105

0 commit comments

Comments
 (0)