Skip to content

Commit

Permalink
clean up types
Browse files Browse the repository at this point in the history
  • Loading branch information
huozhi committed Dec 12, 2024
1 parent ab14892 commit a510ad9
Show file tree
Hide file tree
Showing 5 changed files with 9 additions and 11 deletions.
2 changes: 1 addition & 1 deletion packages/next/src/client/components/app-router.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand Down Expand Up @@ -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
Expand Down Expand Up @@ -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,
Expand Down Expand Up @@ -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])
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -108,6 +108,7 @@ describe('findHeadInCache', () => {
expect(result).not.toBeNull()

const [cacheNode, key] = result!
expect(cacheNode).toBe(null)
expect(cacheNode.head[1]).toMatchObject(
<>
<title>About page!</title>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand Down Expand Up @@ -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(
Expand Down
2 changes: 1 addition & 1 deletion packages/next/src/server/app-render/types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -234,7 +234,7 @@ export type InitialRSCPayload = {
c: string[]
/** couldBeIntercepted */
i: boolean
/** initialFlightData: [tree, seedData, [viewport, metadata]] */
/** initialFlightData */
f: FlightDataPath[]
/** missingSlots */
m: Set<string> | undefined
Expand Down

0 comments on commit a510ad9

Please sign in to comment.