Skip to content

Commit 79f4907

Browse files
authored
feat!: add missing server-only props to custom RSCs, improve req.user type, clean-up ui imports (#6355)
1 parent 6a0fffe commit 79f4907

File tree

83 files changed

+583
-303
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

83 files changed

+583
-303
lines changed

.eslintignore

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -11,3 +11,4 @@
1111
playwright.config.ts
1212
jest.config.js
1313
test/live-preview/next-app
14+
tsconfig.tsbuildinfo

.idea/payload.iml

Lines changed: 27 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

.prettierignore

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -13,3 +13,4 @@ tsconfig.json
1313
packages/payload/*.js
1414
packages/payload/*.d.ts
1515
payload-types.ts
16+
tsconfig.tsbuildinfo

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

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -89,7 +89,6 @@ export const RootLayout = async ({
8989
DefaultEditView,
9090
DefaultListView,
9191
children,
92-
config,
9392
i18n,
9493
payload,
9594
})

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

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -77,7 +77,15 @@ export const Account: React.FC<AdminViewProps> = ({ initPageResult, params, sear
7777
}
7878
DefaultComponent={EditView}
7979
componentProps={viewComponentProps}
80-
payload={payload}
80+
serverOnlyProps={{
81+
i18n,
82+
locale,
83+
params,
84+
payload,
85+
permissions,
86+
searchParams,
87+
user,
88+
}}
8189
/>
8290
</FormQueryParamsProvider>
8391
</DocumentInfoProvider>

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

Lines changed: 40 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
import type { Permissions } from 'payload/auth'
2-
import type { Payload, SanitizedConfig, VisibleEntities } from 'payload/types'
2+
import type { ServerProps } from 'payload/config'
3+
import type { VisibleEntities } from 'payload/types'
34

45
import { Gutter } from '@payloadcms/ui/elements/Gutter'
56
import { SetStepNav } from '@payloadcms/ui/elements/StepNav'
@@ -12,36 +13,66 @@ import './index.scss'
1213

1314
const baseClass = 'dashboard'
1415

15-
export type DashboardProps = {
16+
export type DashboardProps = ServerProps & {
1617
Link: React.ComponentType<any>
17-
config: SanitizedConfig
18-
payload: Payload
18+
1919
permissions: Permissions
2020
visibleEntities: VisibleEntities
2121
}
2222

2323
export const DefaultDashboard: React.FC<DashboardProps> = (props) => {
2424
const {
2525
Link,
26-
config: {
27-
admin: {
28-
components: { afterDashboard, beforeDashboard },
26+
i18n,
27+
locale,
28+
params,
29+
payload: {
30+
config: {
31+
admin: {
32+
components: { afterDashboard, beforeDashboard },
33+
},
2934
},
3035
},
3136
payload,
3237
permissions,
38+
searchParams,
39+
user,
3340
visibleEntities,
3441
} = props
3542

3643
const BeforeDashboards = Array.isArray(beforeDashboard)
3744
? beforeDashboard.map((Component, i) => (
38-
<WithServerSideProps Component={Component} key={i} payload={payload} />
45+
<WithServerSideProps
46+
Component={Component}
47+
key={i}
48+
serverOnlyProps={{
49+
i18n,
50+
locale,
51+
params,
52+
payload,
53+
permissions,
54+
searchParams,
55+
user,
56+
}}
57+
/>
3958
))
4059
: null
4160

4261
const AfterDashboards = Array.isArray(afterDashboard)
4362
? afterDashboard.map((Component, i) => (
44-
<WithServerSideProps Component={Component} key={i} payload={payload} />
63+
<WithServerSideProps
64+
Component={Component}
65+
key={i}
66+
serverOnlyProps={{
67+
i18n,
68+
locale,
69+
params,
70+
payload,
71+
permissions,
72+
searchParams,
73+
user,
74+
}}
75+
/>
4576
))
4677
: null
4778

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

Lines changed: 19 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -13,10 +13,12 @@ export { generateDashboardMetadata } from './meta.js'
1313

1414
const Link = (LinkImport.default || LinkImport) as unknown as typeof LinkImport.default
1515

16-
export const Dashboard: React.FC<AdminViewProps> = ({ initPageResult }) => {
16+
export const Dashboard: React.FC<AdminViewProps> = ({ initPageResult, params, searchParams }) => {
1717
const {
18+
locale,
1819
permissions,
1920
req: {
21+
i18n,
2022
payload: { config },
2123
payload,
2224
user,
@@ -26,10 +28,15 @@ export const Dashboard: React.FC<AdminViewProps> = ({ initPageResult }) => {
2628

2729
const CustomDashboardComponent = config.admin.components?.views?.Dashboard
2830

29-
const viewComponentProps: Omit<DashboardProps, 'payload'> = {
31+
const viewComponentProps: DashboardProps = {
3032
Link,
31-
config,
33+
i18n,
34+
locale,
35+
params,
36+
payload,
3237
permissions,
38+
searchParams,
39+
user,
3340
visibleEntities,
3441
}
3542

@@ -42,7 +49,15 @@ export const Dashboard: React.FC<AdminViewProps> = ({ initPageResult }) => {
4249
}
4350
DefaultComponent={DefaultDashboard}
4451
componentProps={viewComponentProps}
45-
payload={payload}
52+
serverOnlyProps={{
53+
i18n,
54+
locale,
55+
params,
56+
payload,
57+
permissions,
58+
searchParams,
59+
user,
60+
}}
4661
/>
4762
</Fragment>
4863
)

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

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -220,7 +220,15 @@ export const Document: React.FC<AdminViewProps> = async ({
220220
CustomComponent={ViewOverride || CustomView}
221221
DefaultComponent={DefaultView}
222222
componentProps={viewComponentProps}
223-
payload={payload}
223+
serverOnlyProps={{
224+
i18n,
225+
locale,
226+
params,
227+
payload,
228+
permissions,
229+
searchParams,
230+
user,
231+
}}
224232
/>
225233
)}
226234
</FormQueryParamsProvider>

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

Lines changed: 16 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -18,11 +18,17 @@ import { DefaultListView } from './Default/index.js'
1818

1919
export { generateListMetadata } from './meta.js'
2020

21-
export const ListView: React.FC<AdminViewProps> = async ({ initPageResult, searchParams }) => {
21+
export const ListView: React.FC<AdminViewProps> = async ({
22+
initPageResult,
23+
params,
24+
searchParams,
25+
}) => {
2226
const {
2327
collectionConfig,
28+
locale: fullLocale,
2429
permissions,
2530
req: {
31+
i18n,
2632
locale,
2733
payload,
2834
payload: { config },
@@ -142,7 +148,15 @@ export const ListView: React.FC<AdminViewProps> = async ({ initPageResult, searc
142148
CustomComponent={CustomListView}
143149
DefaultComponent={DefaultListView}
144150
componentProps={viewComponentProps}
145-
payload={payload}
151+
serverOnlyProps={{
152+
i18n,
153+
locale: fullLocale,
154+
params,
155+
payload,
156+
permissions,
157+
searchParams,
158+
user,
159+
}}
146160
/>
147161
</TableColumnsProvider>
148162
</ListQueryProvider>

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

Lines changed: 38 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -12,10 +12,11 @@ export { generateLoginMetadata } from './meta.js'
1212

1313
export const loginBaseClass = 'login'
1414

15-
export const LoginView: React.FC<AdminViewProps> = ({ initPageResult, searchParams }) => {
16-
const { req } = initPageResult
15+
export const LoginView: React.FC<AdminViewProps> = ({ initPageResult, params, searchParams }) => {
16+
const { locale, permissions, req } = initPageResult
1717

1818
const {
19+
i18n,
1920
payload: { config },
2021
payload,
2122
user,
@@ -29,13 +30,37 @@ export const LoginView: React.FC<AdminViewProps> = ({ initPageResult, searchPara
2930

3031
const BeforeLogins = Array.isArray(beforeLogin)
3132
? beforeLogin.map((Component, i) => (
32-
<WithServerSideProps Component={Component} key={i} payload={payload} />
33+
<WithServerSideProps
34+
Component={Component}
35+
key={i}
36+
serverOnlyProps={{
37+
i18n,
38+
locale,
39+
params,
40+
payload,
41+
permissions,
42+
searchParams,
43+
user,
44+
}}
45+
/>
3346
))
3447
: null
3548

3649
const AfterLogins = Array.isArray(afterLogin)
3750
? afterLogin.map((Component, i) => (
38-
<WithServerSideProps Component={Component} key={i} payload={payload} />
51+
<WithServerSideProps
52+
Component={Component}
53+
key={i}
54+
serverOnlyProps={{
55+
i18n,
56+
locale,
57+
params,
58+
payload,
59+
permissions,
60+
searchParams,
61+
user,
62+
}}
63+
/>
3964
))
4065
: null
4166

@@ -48,7 +73,15 @@ export const LoginView: React.FC<AdminViewProps> = ({ initPageResult, searchPara
4873
return (
4974
<Fragment>
5075
<div className={`${loginBaseClass}__brand`}>
51-
<Logo payload={payload} />
76+
<Logo
77+
i18n={i18n}
78+
locale={locale}
79+
params={params}
80+
payload={payload}
81+
permissions={permissions}
82+
searchParams={searchParams}
83+
user={user}
84+
/>
5285
</div>
5386
{Array.isArray(BeforeLogins) && BeforeLogins.map((Component) => Component)}
5487
{!collectionConfig?.auth?.disableLocalStrategy && <LoginForm searchParams={searchParams} />}

0 commit comments

Comments
 (0)