Skip to content

Commit 7a94cc1

Browse files
authored
refactor(next): remove unnecessary react hooks from DefaultTemplate rsc (#14876)
This remove unnecessary useMemo react hooks from `DefaultTemplate`. `DefaultTemplate` is a React Server Component, so those hooks didn't do anything and shouldn't be used.
1 parent 10a8f0f commit 7a94cc1

File tree

1 file changed

+35
-63
lines changed

1 file changed

+35
-63
lines changed

packages/next/src/templates/Default/index.tsx

Lines changed: 35 additions & 63 deletions
Original file line numberDiff line numberDiff line change
@@ -69,72 +69,44 @@ export const DefaultTemplate: React.FC<DefaultTemplateProps> = ({
6969
} = {},
7070
} = payload.config || {}
7171

72-
const clientProps = React.useMemo(() => {
73-
return {
74-
documentSubViewType,
75-
viewType,
76-
visibleEntities,
77-
}
78-
}, [documentSubViewType, viewType, visibleEntities])
79-
80-
const serverProps = React.useMemo<ServerProps>(
81-
() => ({
82-
collectionSlug,
83-
docID,
84-
globalSlug,
85-
i18n,
86-
locale,
87-
params,
88-
payload,
89-
permissions,
90-
req,
91-
searchParams,
92-
user,
93-
}),
94-
[
95-
i18n,
96-
locale,
97-
params,
98-
payload,
99-
permissions,
100-
searchParams,
101-
user,
102-
globalSlug,
103-
collectionSlug,
104-
docID,
105-
req,
106-
],
107-
)
72+
const clientProps = {
73+
documentSubViewType,
74+
viewType,
75+
visibleEntities,
76+
}
10877

109-
const { Actions } = React.useMemo<{
110-
Actions: Record<string, React.ReactNode>
111-
}>(() => {
112-
return {
113-
Actions: viewActions
114-
? viewActions.reduce((acc, action) => {
115-
if (action) {
116-
if (typeof action === 'object') {
117-
acc[action.path] = RenderServerComponent({
118-
clientProps,
119-
Component: action,
120-
importMap: payload.importMap,
121-
serverProps,
122-
})
123-
} else {
124-
acc[action] = RenderServerComponent({
125-
clientProps,
126-
Component: action,
127-
importMap: payload.importMap,
128-
serverProps,
129-
})
130-
}
131-
}
78+
const serverProps: {
79+
collectionSlug: string
80+
docID: number | string
81+
globalSlug: string
82+
req: PayloadRequest
83+
} & ServerProps = {
84+
collectionSlug,
85+
docID,
86+
globalSlug,
87+
i18n,
88+
locale,
89+
params,
90+
payload,
91+
permissions,
92+
req,
93+
searchParams,
94+
user,
95+
}
13296

133-
return acc
134-
}, {})
135-
: undefined,
97+
const Actions: Record<string, React.ReactNode> = {}
98+
for (const action of viewActions ?? []) {
99+
if (!action) {
100+
continue
136101
}
137-
}, [payload, serverProps, viewActions, clientProps])
102+
const key = typeof action === 'object' ? action.path : action
103+
Actions[key] = RenderServerComponent({
104+
clientProps,
105+
Component: action,
106+
importMap: payload.importMap,
107+
serverProps,
108+
})
109+
}
138110

139111
const NavComponent = RenderServerComponent({
140112
clientProps,

0 commit comments

Comments
 (0)