diff --git a/apps/nextjs/src/app/[locale]/boards/(content)/_creator.tsx b/apps/nextjs/src/app/[locale]/boards/(content)/_creator.tsx index 3314dee3c..106f1f562 100644 --- a/apps/nextjs/src/app/[locale]/boards/(content)/_creator.tsx +++ b/apps/nextjs/src/app/[locale]/boards/(content)/_creator.tsx @@ -1,3 +1,4 @@ +import { cache } from "react"; import type { Metadata } from "next"; import { TRPCError } from "@trpc/server"; @@ -34,17 +35,20 @@ interface Props { export const createBoardContentPage = >({ getInitialBoardAsync: getInitialBoard, }: Props) => { + const getCachedBoard = cache((_paramsKey: string, params: TParams) => getInitialBoard(params)); + const getBoardForParams = (params: TParams) => getCachedBoard(JSON.stringify(params), params); + return { layout: createBoardLayout({ headerActions: , - getInitialBoardAsync: getInitialBoard, + getInitialBoardAsync: getBoardForParams, }), // eslint-disable-next-line no-restricted-syntax page: async ({ params }: { params: Promise }) => { const resolvedParams = await params; const queryClient = getQueryClient(); - const [board, session] = await Promise.all([getInitialBoard(resolvedParams), auth()]); + const [board, session] = await Promise.all([getBoardForParams(resolvedParams), auth()]); const itemsMap = board.items.reduce((acc, item) => { const existing = acc.get(item.kind); @@ -81,7 +85,7 @@ export const createBoardContentPage = >( }, generateMetadataAsync: async ({ params }: { params: Promise }): Promise => { try { - const board = await getInitialBoard(await params); + const board = await getBoardForParams(await params); const t = await getI18n(); return { @@ -97,7 +101,6 @@ export const createBoardContentPage = >( }, }; } catch (error) { - // Ignore not found errors and return empty metadata if (error instanceof TRPCError && error.code === "NOT_FOUND") { return {}; }