Skip to content

Commit

Permalink
refactor path creation in walkTreeWithFlightRouterState
Browse files Browse the repository at this point in the history
  • Loading branch information
ztanner committed Aug 27, 2024
1 parent 46c6776 commit dadbc5e
Showing 1 changed file with 44 additions and 48 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -184,55 +184,51 @@ export async function walkTreeWithFlightRouterState({
)
}

// Walk through all parallel routes.
const paths: FlightDataPath[] = (
await Promise.all(
parallelRoutesKeys.map(async (parallelRouteKey) => {
// for (const parallelRouteKey of parallelRoutesKeys) {
const parallelRoute = parallelRoutes[parallelRouteKey]

const currentSegmentPath: FlightSegmentPath = isFirst
? [parallelRouteKey]
: [actualSegment, parallelRouteKey]
const paths: FlightDataPath[] = []

const path = await walkTreeWithFlightRouterState({
ctx,
createSegmentPath: (child) => {
return createSegmentPath([...currentSegmentPath, ...child])
},
loaderTreeToFilter: parallelRoute,
parentParams: currentParams,
flightRouterState:
flightRouterState && flightRouterState[1][parallelRouteKey],
parentRendered: parentRendered || renderComponentsOnThisLevel,
isFirst: false,
rscPayloadHead,
injectedCSS: injectedCSSWithCurrentLayout,
injectedJS: injectedJSWithCurrentLayout,
injectedFontPreloadTags: injectedFontPreloadTagsWithCurrentLayout,
rootLayoutIncluded: rootLayoutIncludedAtThisLevelOrAbove,
getMetadataReady,
preloadCallbacks,
})

return path
.map((item) => {
// we don't need to send over default routes in the flight data
// because they are always ignored by the client, unless it's a refetch
if (
item[0] === DEFAULT_SEGMENT_KEY &&
flightRouterState &&
!!flightRouterState[1][parallelRouteKey][0] &&
flightRouterState[1][parallelRouteKey][3] !== 'refetch'
) {
return null
}
return [actualSegment, parallelRouteKey, ...item]
})
.filter(Boolean) as FlightDataPath[]
})
)
).flat()
// Walk through all parallel routes.
for (const parallelRouteKey of parallelRoutesKeys) {
const parallelRoute = parallelRoutes[parallelRouteKey]

const currentSegmentPath: FlightSegmentPath = isFirst
? [parallelRouteKey]
: [actualSegment, parallelRouteKey]

const subPaths = await walkTreeWithFlightRouterState({
ctx,
createSegmentPath: (child) => {
return createSegmentPath([...currentSegmentPath, ...child])
},
loaderTreeToFilter: parallelRoute,
parentParams: currentParams,
flightRouterState:
flightRouterState && flightRouterState[1][parallelRouteKey],
parentRendered: parentRendered || renderComponentsOnThisLevel,
isFirst: false,
rscPayloadHead,
injectedCSS: injectedCSSWithCurrentLayout,
injectedJS: injectedJSWithCurrentLayout,
injectedFontPreloadTags: injectedFontPreloadTagsWithCurrentLayout,
rootLayoutIncluded: rootLayoutIncludedAtThisLevelOrAbove,
getMetadataReady,
preloadCallbacks,
})

for (const subPath of subPaths) {
// we don't need to send over default routes in the flight data
// because they are always ignored by the client, unless it's a refetch
if (
subPath[0] === DEFAULT_SEGMENT_KEY &&
flightRouterState &&
!!flightRouterState[1][parallelRouteKey][0] &&
flightRouterState[1][parallelRouteKey][3] !== 'refetch'
) {
continue
}

paths.push([actualSegment, parallelRouteKey, ...subPath])
}
}

return paths
}

0 comments on commit dadbc5e

Please sign in to comment.