Skip to content

Commit

Permalink
Next.js: Support v15.1
Browse files Browse the repository at this point in the history
  • Loading branch information
valentinpalkovic committed Dec 15, 2024
1 parent b6a1547 commit 986b602
Show file tree
Hide file tree
Showing 2 changed files with 37 additions and 3 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -44,8 +44,6 @@ function getSelectedParams(currentTree: FlightRouterState, params: Params = {}):
continue;
}

// Ensure catchAll and optional catchall are turned into an array

// Ensure catchAll and optional catchall are turned into an array
const isCatchAll = isDynamicParameter && (segment[2] === 'c' || segment[2] === 'oc');

Expand Down Expand Up @@ -82,6 +80,16 @@ export const AppRouterProvider: React.FC<React.PropsWithChildren<AppRouterProvid
return getSelectedParams(tree);
}, [tree]);

const newLazyCacheNode = {
lazyData: null,
rsc: null,
prefetchRsc: null,
head: null,
prefetchHead: null,
parallelRoutes: new Map(),
loading: null,
};

// https://github.com/vercel/next.js/blob/canary/packages/next/src/client/components/app-router.tsx#L436
return (
<PathParamsContext.Provider value={pathParams}>
Expand All @@ -106,10 +114,18 @@ export const AppRouterProvider: React.FC<React.PropsWithChildren<AppRouterProvid
<AppRouterContext.Provider value={getRouter()}>
<LayoutRouterContext.Provider
value={{
// TODO Remove when dropping Next.js < v15.2
childNodes: new Map(),
loading: null,
tree,
// TODO END

// START Next.js v15.2 support
// @ts-expect-error Only available in Next.js >v15.2
parentTree: tree,
parentCacheNode: newLazyCacheNode,
// END
url: pathname,
loading: null,
}}
>
{children}
Expand Down
18 changes: 18 additions & 0 deletions code/frameworks/nextjs/src/routing/app-router-provider.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -80,6 +80,16 @@ export const AppRouterProvider: React.FC<React.PropsWithChildren<AppRouterProvid
return getSelectedParams(tree);
}, [tree]);

const newLazyCacheNode = {
lazyData: null,
rsc: null,
prefetchRsc: null,
head: null,
prefetchHead: null,
parallelRoutes: new Map(),
loading: null,
};

// https://github.com/vercel/next.js/blob/canary/packages/next/src/client/components/app-router.tsx#L436
return (
<PathParamsContext.Provider value={pathParams}>
Expand All @@ -104,8 +114,16 @@ export const AppRouterProvider: React.FC<React.PropsWithChildren<AppRouterProvid
<AppRouterContext.Provider value={getRouter()}>
<LayoutRouterContext.Provider
value={{
// TODO Remove when dropping Next.js < v15.2
childNodes: new Map(),
tree,
// TODO END

// START Next.js v15.2 support
// @ts-expect-error Only available in Next.js >v15.2
parentTree: tree,
parentCacheNode: newLazyCacheNode,
// END
url: pathname,
loading: null,
}}
Expand Down

0 comments on commit 986b602

Please sign in to comment.