From 0303b78d628422bac99457fd8d6bcf82844c18d1 Mon Sep 17 00:00:00 2001 From: Said Akhrarov <36972061+akhrarovsaid@users.noreply.github.com> Date: Wed, 11 Dec 2024 12:19:37 -0500 Subject: [PATCH] fix(next): thread default ServerProps to view actions and other components that were missing (#9868) This PR threads default `serverProps` to Edit and List view action slots, as well as other various components that were missing them. --------- Co-authored-by: Alessio Gravili --- packages/next/src/templates/Default/index.tsx | 42 +++++++++---------- .../views/Document/renderDocumentSlots.tsx | 14 ++++++- packages/payload/src/config/types.ts | 2 +- 3 files changed, 35 insertions(+), 23 deletions(-) diff --git a/packages/next/src/templates/Default/index.tsx b/packages/next/src/templates/Default/index.tsx index 32b9019fd43..b410ee6a15f 100644 --- a/packages/next/src/templates/Default/index.tsx +++ b/packages/next/src/templates/Default/index.tsx @@ -48,6 +48,20 @@ export const DefaultTemplate: React.FC = ({ } = {}, } = payload.config || {} + const serverProps = React.useMemo( + () => ({ + i18n, + locale, + params, + payload, + permissions, + searchParams, + user, + visibleEntities, + }), + [i18n, locale, params, payload, permissions, searchParams, user, visibleEntities], + ) + const { Actions } = React.useMemo<{ Actions: Record }>(() => { @@ -59,11 +73,13 @@ export const DefaultTemplate: React.FC = ({ acc[action.path] = RenderServerComponent({ Component: action, importMap: payload.importMap, + serverProps, }) } else { acc[action] = RenderServerComponent({ Component: action, importMap: payload.importMap, + serverProps, }) } } @@ -72,23 +88,14 @@ export const DefaultTemplate: React.FC = ({ }, {}) : undefined, } - }, [viewActions, payload]) + }, [payload, serverProps, viewActions]) const NavComponent = RenderServerComponent({ clientProps: { clientProps: { visibleEntities } }, Component: CustomNav, Fallback: DefaultNav, importMap: payload.importMap, - serverProps: { - i18n, - locale, - params, - payload, - permissions, - searchParams, - user, - visibleEntities, - }, + serverProps, }) return ( @@ -99,16 +106,7 @@ export const DefaultTemplate: React.FC = ({ clientProps: { clientProps: { visibleEntities } }, Component: CustomHeader, importMap: payload.importMap, - serverProps: { - i18n, - locale, - params, - payload, - permissions, - searchParams, - user, - visibleEntities, - }, + serverProps, })}