Skip to content

Commit a98a398

Browse files
authored
perf(ui): remove unnecessary deepCopy in reduceToSerializableFields (#10667)
1 parent 91ed882 commit a98a398

File tree

1 file changed

+14
-17
lines changed

1 file changed

+14
-17
lines changed
Lines changed: 14 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -1,35 +1,32 @@
11
import { type FormField, type FormState } from 'payload'
2-
import { deepCopyObjectComplex } from 'payload/shared'
32

43
type BlacklistedKeys = 'customComponents' | 'validate'
54
const blacklistedKeys: BlacklistedKeys[] = ['validate', 'customComponents']
65

76
const sanitizeField = (incomingField: FormField): FormField => {
8-
const field = deepCopyObjectComplex(incomingField)
7+
const field = { ...incomingField } // shallow copy, as we only need to remove top-level keys
98

10-
blacklistedKeys.forEach((key) => {
9+
for (const key of blacklistedKeys) {
1110
delete field[key]
12-
})
11+
}
1312

1413
return field
1514
}
1615

17-
/*
18-
Takes in FormState and removes fields that are not serializable.
19-
Returns FormState without blacklisted keys.
20-
**/
16+
/**
17+
* Takes in FormState and removes fields that are not serializable.
18+
* Returns FormState without blacklisted keys.
19+
*/
2120
export const reduceToSerializableFields = (
2221
fields: FormState,
2322
): {
2423
[key: string]: Omit<FormField, BlacklistedKeys>
2524
} => {
26-
return Object.keys(fields).reduce(
27-
(acc, key) => {
28-
acc[key] = sanitizeField(fields[key])
29-
return acc
30-
},
31-
{} as {
32-
[key: string]: Omit<FormField, BlacklistedKeys>
33-
},
34-
)
25+
const result: Record<string, Omit<FormField, BlacklistedKeys>> = {}
26+
27+
for (const key in fields) {
28+
result[key] = sanitizeField(fields[key])
29+
}
30+
31+
return result
3532
}

0 commit comments

Comments
 (0)