Skip to content

Commit 0d98b4b

Browse files
authored
fix!: some custom components were not handled properly if they are RSCs (#6315)
**Breaking:** The following, exported components now need the `payload` object as a prop rather than the `config` object: - `RenderCustomComponent` (optional) - `Logo` - `DefaultTemplate` - `DefaultNav`
1 parent 23c7ab2 commit 0d98b4b

File tree

16 files changed

+94
-38
lines changed

16 files changed

+94
-38
lines changed

packages/next/src/views/Account/index.tsx

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -77,6 +77,7 @@ export const Account: React.FC<AdminViewProps> = ({ initPageResult, params, sear
7777
}
7878
DefaultComponent={EditView}
7979
componentProps={viewComponentProps}
80+
payload={payload}
8081
/>
8182
</FormQueryParamsProvider>
8283
</DocumentInfoProvider>

packages/next/src/views/Dashboard/Default/index.tsx

Lines changed: 19 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,9 @@
11
import type { Permissions } from 'payload/auth'
2-
import type { SanitizedConfig, VisibleEntities } from 'payload/types'
2+
import type { Payload, SanitizedConfig, VisibleEntities } from 'payload/types'
33

44
import { Gutter } from '@payloadcms/ui/elements/Gutter'
55
import { SetStepNav } from '@payloadcms/ui/elements/StepNav'
6+
import { WithServerSideProps } from '@payloadcms/ui/elements/WithServerSideProps'
67
import { SetViewActions } from '@payloadcms/ui/providers/Actions'
78
import React from 'react'
89

@@ -14,6 +15,7 @@ const baseClass = 'dashboard'
1415
export type DashboardProps = {
1516
Link: React.ComponentType<any>
1617
config: SanitizedConfig
18+
payload: Payload
1719
permissions: Permissions
1820
visibleEntities: VisibleEntities
1921
}
@@ -26,24 +28,36 @@ export const DefaultDashboard: React.FC<DashboardProps> = (props) => {
2628
components: { afterDashboard, beforeDashboard },
2729
},
2830
},
31+
payload,
2932
permissions,
3033
visibleEntities,
3134
} = props
3235

36+
const BeforeDashboards = Array.isArray(beforeDashboard)
37+
? beforeDashboard.map((Component, i) => (
38+
<WithServerSideProps Component={Component} key={i} payload={payload} />
39+
))
40+
: null
41+
42+
const AfterDashboards = Array.isArray(afterDashboard)
43+
? afterDashboard.map((Component, i) => (
44+
<WithServerSideProps Component={Component} key={i} payload={payload} />
45+
))
46+
: null
47+
3348
return (
3449
<div className={baseClass}>
3550
<SetStepNav nav={[]} />
3651
<SetViewActions actions={[]} />
3752
<Gutter className={`${baseClass}__wrap`}>
38-
{Array.isArray(beforeDashboard) &&
39-
beforeDashboard.map((Component, i) => <Component key={i} />)}
53+
{Array.isArray(BeforeDashboards) && BeforeDashboards.map((Component) => Component)}
54+
4055
<DefaultDashboardClient
4156
Link={Link}
4257
permissions={permissions}
4358
visibleEntities={visibleEntities}
4459
/>
45-
{Array.isArray(afterDashboard) &&
46-
afterDashboard.map((Component, i) => <Component key={i} />)}
60+
{Array.isArray(AfterDashboards) && AfterDashboards.map((Component) => Component)}
4761
</Gutter>
4862
</div>
4963
)

packages/next/src/views/Dashboard/index.tsx

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -18,14 +18,15 @@ export const Dashboard: React.FC<AdminViewProps> = ({ initPageResult }) => {
1818
permissions,
1919
req: {
2020
payload: { config },
21+
payload,
2122
user,
2223
},
2324
visibleEntities,
2425
} = initPageResult
2526

2627
const CustomDashboardComponent = config.admin.components?.views?.Dashboard
2728

28-
const viewComponentProps: DashboardProps = {
29+
const viewComponentProps: Omit<DashboardProps, 'payload'> = {
2930
Link,
3031
config,
3132
permissions,
@@ -41,6 +42,7 @@ export const Dashboard: React.FC<AdminViewProps> = ({ initPageResult }) => {
4142
}
4243
DefaultComponent={DefaultDashboard}
4344
componentProps={viewComponentProps}
45+
payload={payload}
4446
/>
4547
</Fragment>
4648
)

packages/next/src/views/Document/index.tsx

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -220,6 +220,7 @@ export const Document: React.FC<AdminViewProps> = async ({
220220
CustomComponent={ViewOverride || CustomView}
221221
DefaultComponent={DefaultView}
222222
componentProps={viewComponentProps}
223+
payload={payload}
223224
/>
224225
)}
225226
</FormQueryParamsProvider>

packages/next/src/views/List/index.tsx

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -142,6 +142,7 @@ export const ListView: React.FC<AdminViewProps> = async ({ initPageResult, searc
142142
CustomComponent={CustomListView}
143143
DefaultComponent={DefaultListView}
144144
componentProps={viewComponentProps}
145+
payload={payload}
145146
/>
146147
</TableColumnsProvider>
147148
</ListQueryProvider>

packages/next/src/views/Login/index.tsx

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -48,7 +48,7 @@ export const LoginView: React.FC<AdminViewProps> = ({ initPageResult, searchPara
4848
return (
4949
<Fragment>
5050
<div className={`${loginBaseClass}__brand`}>
51-
<Logo config={config} />
51+
<Logo payload={payload} />
5252
</div>
5353
{Array.isArray(BeforeLogins) && BeforeLogins.map((Component) => Component)}
5454
{!collectionConfig?.auth?.disableLocalStrategy && <LoginForm searchParams={searchParams} />}

packages/next/src/views/NotFound/index.tsx

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -60,7 +60,7 @@ export const NotFoundPage = async ({
6060
<Fragment>
6161
<HydrateClientUser permissions={initPageResult.permissions} user={initPageResult.req.user} />
6262
<DefaultTemplate
63-
config={initPageResult.req.payload.config}
63+
payload={initPageResult.req.payload}
6464
visibleEntities={initPageResult.visibleEntities}
6565
>
6666
<NotFoundClient />

packages/next/src/views/Root/index.tsx

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -87,7 +87,10 @@ export const RootPage = async ({
8787
<MinimalTemplate className={templateClassName}>{RenderedView}</MinimalTemplate>
8888
)}
8989
{templateType === 'default' && (
90-
<DefaultTemplate config={config} visibleEntities={initPageResult.visibleEntities}>
90+
<DefaultTemplate
91+
payload={initPageResult?.req.payload}
92+
visibleEntities={initPageResult.visibleEntities}
93+
>
9194
{RenderedView}
9295
</DefaultTemplate>
9396
)}

packages/next/src/views/Verify/index.tsx

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,7 @@ export const Verify: React.FC<AdminViewProps> = async ({ initPageResult, params
1818

1919
const {
2020
payload: { config },
21+
payload,
2122
} = req
2223

2324
const {
@@ -42,7 +43,7 @@ export const Verify: React.FC<AdminViewProps> = async ({ initPageResult, params
4243
return (
4344
<React.Fragment>
4445
<div className={`${verifyBaseClass}__brand`}>
45-
<Logo config={config} />
46+
<Logo payload={payload} />
4647
</div>
4748
<h2>{textToRender}</h2>
4849
</React.Fragment>

packages/payload/src/fields/config/types.ts

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -121,6 +121,9 @@ type Admin = {
121121
Cell?: CustomComponent
122122
Description?: DescriptionComponent
123123
Field?: CustomComponent
124+
/**
125+
* The Filter component has to be a client component
126+
*/
124127
Filter?: React.ComponentType<any>
125128
}
126129
/**
@@ -447,6 +450,9 @@ export type UIField = {
447450
components?: {
448451
Cell?: CustomComponent
449452
Field: CustomComponent
453+
/**
454+
* The Filter component has to be a client component
455+
*/
450456
Filter?: React.ComponentType<any>
451457
}
452458
condition?: Condition

0 commit comments

Comments
 (0)