Skip to content

Commit 74f935b

Browse files
authored
fix: auth fields distrupt field paths within the field schema map (#11861)
Within auth-enabled collections, we inject the `password` and `confirmPassword` fields into the field schema map. While this is fine within the edit view where these fields are used, this breaks field paths within the version diff view where unnamed fields are no longer able to lookup their corresponding config. This is because the presence of these injected fields increments the field indices by two. A temporary fix for this is to simply inject these fields _last_ into the schema map. This way their presence does not disrupt field path generation. A long term fix should be implemented, however, where these fields actually exist on the collection config itself. This way no config mutation would be required as the sanitized config would the single source of truth. To do this, we'd need to ensure that these fields do not appear in any APIs, and that they do not generate types, etc.
1 parent 73fc3c6 commit 74f935b

File tree

5 files changed

+10
-5
lines changed

5 files changed

+10
-5
lines changed

packages/next/src/views/Version/RenderFieldsToDiff/buildVersionFields.tsx

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -75,8 +75,10 @@ export const buildVersionFields = ({
7575
} => {
7676
const versionFields: VersionField[] = []
7777
let fieldIndex = -1
78+
7879
for (const field of fields) {
7980
fieldIndex++
81+
8082
if (fieldIsID(field)) {
8183
continue
8284
}

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

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -37,6 +37,7 @@ export async function VersionView(props: DocumentViewServerProps) {
3737
const localeCodesFromParams = searchParams.localeCodes
3838
? JSON.parse(searchParams.localeCodes as string)
3939
: null
40+
4041
const comparisonVersionIDFromParams: string = searchParams.compareValue as string
4142

4243
const modifiedOnly: boolean = searchParams.modifiedOnly === 'true'
@@ -88,7 +89,7 @@ export async function VersionView(props: DocumentViewServerProps) {
8889
status: 'published',
8990
})
9091
}
91-
} catch (error) {
92+
} catch (_err) {
9293
return notFound()
9394
}
9495
}
@@ -129,7 +130,7 @@ export async function VersionView(props: DocumentViewServerProps) {
129130
status: 'published',
130131
})
131132
}
132-
} catch (error) {
133+
} catch (_err) {
133134
return notFound()
134135
}
135136
}

packages/ui/src/utilities/buildClientFieldSchemaMap/index.ts

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -49,7 +49,8 @@ export const buildClientFieldSchemaMap = (args: {
4949
if (matchedCollection.auth && !matchedCollection.auth.disableLocalStrategy) {
5050
;(baseAuthFields[0] as TextFieldClient).label = i18n.t('general:password')
5151
;(baseAuthFields[1] as TextFieldClient).label = i18n.t('authentication:confirmPassword')
52-
fieldsToSet = baseAuthFields.concat(fieldsToSet)
52+
// Place these fields _last_ to ensure they do not disrupt field paths in the field schema map
53+
fieldsToSet = fieldsToSet.concat(baseAuthFields)
5354
}
5455

5556
clientSchemaMap.set(collectionSlug, {

packages/ui/src/utilities/buildFieldSchemaMap/index.ts

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -44,7 +44,8 @@ export const buildFieldSchemaMap = (args: {
4444
if (matchedCollection.auth && !matchedCollection.auth.disableLocalStrategy) {
4545
;(baseAuthFields[0] as TextField).label = i18n.t('general:password')
4646
;(baseAuthFields[1] as TextField).label = i18n.t('authentication:confirmPassword')
47-
fieldsToSet = baseAuthFields.concat(fieldsToSet)
47+
// Place these fields _last_ to ensure they do not disrupt field paths in the field schema map
48+
fieldsToSet = fieldsToSet.concat(baseAuthFields)
4849
}
4950

5051
schemaMap.set(collectionSlug, {

tsconfig.base.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -31,7 +31,7 @@
3131
}
3232
],
3333
"paths": {
34-
"@payload-config": ["./test/query-presets/config.ts"],
34+
"@payload-config": ["./test/_community/config.ts"],
3535
"@payloadcms/admin-bar": ["./packages/admin-bar/src"],
3636
"@payloadcms/live-preview": ["./packages/live-preview/src"],
3737
"@payloadcms/live-preview-react": ["./packages/live-preview-react/src/index.ts"],

0 commit comments

Comments
 (0)