Next.js: Support v15.1

This commit is contained in:
Valentin Palkovic 2024-12-15 11:20:16 +01:00
parent b6a1547dd5
commit fa46d28f93
2 changed files with 37 additions and 3 deletions

View File

@ -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');
@ -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}>
@ -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.1.1
childNodes: new Map(),
loading: null,
tree,
// TODO END
// START Next.js v15.2 support
// @ts-expect-error Only available in Next.js >= v15.1.1
parentTree: tree,
parentCacheNode: newLazyCacheNode,
// END
url: pathname,
loading: null,
}}
>
{children}

View File

@ -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}>
@ -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.1.1
childNodes: new Map(),
tree,
// TODO END
// START Next.js v15.2 support
// @ts-expect-error Only available in Next.js >= v15.1.1
parentTree: tree,
parentCacheNode: newLazyCacheNode,
// END
url: pathname,
loading: null,
}}