From d683bc41cc90abcd2c5f064d3f1c2e9a875b09a8 Mon Sep 17 00:00:00 2001 From: Jiachi Liu Date: Thu, 12 Dec 2024 21:48:23 +0100 Subject: [PATCH] clean up types --- packages/next/src/client/components/app-router.tsx | 2 +- .../components/router-reducer/ppr-navigations.ts | 11 ++++------- .../reducers/find-head-in-cache.test.tsx | 1 + .../src/client/components/segment-cache/navigation.ts | 4 ++-- packages/next/src/server/app-render/types.ts | 2 +- 5 files changed, 9 insertions(+), 11 deletions(-) diff --git a/packages/next/src/client/components/app-router.tsx b/packages/next/src/client/components/app-router.tsx index fa7b67f837cab..6bcf12ef6cbbe 100644 --- a/packages/next/src/client/components/app-router.tsx +++ b/packages/next/src/client/components/app-router.tsx @@ -219,7 +219,7 @@ function Head({ // If this segment has a `prefetchHead`, it's the statically prefetched data. // We should use that on initial render instead of `head`. Then we'll switch // to `head` when the dynamic response streams in. - const head = headCacheNode !== null ? headCacheNode.head[1] : null + const head = headCacheNode !== null ? headCacheNode.head : null const prefetchHead = headCacheNode !== null ? headCacheNode.prefetchHead : null diff --git a/packages/next/src/client/components/router-reducer/ppr-navigations.ts b/packages/next/src/client/components/router-reducer/ppr-navigations.ts index b019a41776e3b..1bdcda24dfd47 100644 --- a/packages/next/src/client/components/router-reducer/ppr-navigations.ts +++ b/packages/next/src/client/components/router-reducer/ppr-navigations.ts @@ -70,7 +70,7 @@ export function updateCacheNodeOnNavigation( oldRouterState: FlightRouterState, newRouterState: FlightRouterState, prefetchData: CacheNodeSeedData | null, - prefetchHead: React.ReactNode | null, + prefetchHead: [React.ReactNode | null, React.ReactNode | null], isPrefetchHeadPartial: boolean ): Task | null { // Diff the old and new trees to reuse the shared layouts. @@ -285,7 +285,7 @@ export function updateCacheNodeOnNavigation( function createCacheNodeOnNavigation( routerState: FlightRouterState, prefetchData: CacheNodeSeedData | null, - possiblyPartialPrefetchHead: React.ReactNode | null, + possiblyPartialPrefetchHead: [React.ReactNode | null, React.ReactNode | null], isPrefetchHeadPartial: boolean ): Task { // Same traversal as updateCacheNodeNavigation, but we switch to this path @@ -386,11 +386,7 @@ function createCacheNodeOnNavigation( // `prefetchRsc` field. rsc, prefetchRsc: null, - head: [ - // TODO: change it to support viewport and metadata - isLeafSegment ? possiblyPartialPrefetchHead : null, - isLeafSegment ? possiblyPartialPrefetchHead : null, - ], + head: isLeafSegment ? possiblyPartialPrefetchHead : [null, null], prefetchHead: null, loading, parallelRoutes: cacheNodeChildren, @@ -803,6 +799,7 @@ function finishPendingCacheNode( // a pending promise that needs to be resolved with the dynamic head from // the server. const head = cacheNode.head + // Handle head[0] - viewport and head[1] - metadata if (isDeferredRsc(head[0])) { head[0].resolve(dynamicHead[0]) } diff --git a/packages/next/src/client/components/router-reducer/reducers/find-head-in-cache.test.tsx b/packages/next/src/client/components/router-reducer/reducers/find-head-in-cache.test.tsx index 71dc05f3139da..89707061ca60f 100644 --- a/packages/next/src/client/components/router-reducer/reducers/find-head-in-cache.test.tsx +++ b/packages/next/src/client/components/router-reducer/reducers/find-head-in-cache.test.tsx @@ -108,6 +108,7 @@ describe('findHeadInCache', () => { expect(result).not.toBeNull() const [cacheNode, key] = result! + expect(cacheNode).toBe(null) expect(cacheNode.head[1]).toMatchObject( <> About page! diff --git a/packages/next/src/client/components/segment-cache/navigation.ts b/packages/next/src/client/components/segment-cache/navigation.ts index 7b3ee3417121d..70e8f3445f420 100644 --- a/packages/next/src/client/components/segment-cache/navigation.ts +++ b/packages/next/src/client/components/segment-cache/navigation.ts @@ -125,7 +125,7 @@ function navigateUsingPrefetchedRouteTree( currentFlightRouterState: FlightRouterState, prefetchFlightRouterState: FlightRouterState, prefetchSeedData: CacheNodeSeedData | null, - prefetchHead: React.ReactNode | null, + prefetchHead: [React.ReactNode | null, React.ReactNode | null], isPrefetchHeadPartial: boolean, canonicalUrl: string ): SuccessfulNavigationResult | NoOpNavigationResult { @@ -307,7 +307,7 @@ async function navigateDynamicallyWithNoPrefetch( // In our simulated prefetch payload, we pretend that there's no seed data // nor a prefetch head. const prefetchSeedData = null - const prefetchHead = null + const prefetchHead: [null, null] = [null, null] const isPrefetchHeadPartial = true const canonicalUrl = createCanonicalUrl( diff --git a/packages/next/src/server/app-render/types.ts b/packages/next/src/server/app-render/types.ts index 9da4daf5eca91..543238d79cd3a 100644 --- a/packages/next/src/server/app-render/types.ts +++ b/packages/next/src/server/app-render/types.ts @@ -234,7 +234,7 @@ export type InitialRSCPayload = { c: string[] /** couldBeIntercepted */ i: boolean - /** initialFlightData: [tree, seedData, [viewport, metadata]] */ + /** initialFlightData */ f: FlightDataPath[] /** missingSlots */ m: Set | undefined