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.
This commit is contained in:
Jacob Fletcher
2025-03-25 12:19:29 -04:00
committed by GitHub
parent 73fc3c607a
commit 74f935bfb9
5 changed files with 10 additions and 5 deletions

View File

@@ -75,8 +75,10 @@ export const buildVersionFields = ({
} => {
const versionFields: VersionField[] = []
let fieldIndex = -1
for (const field of fields) {
fieldIndex++
if (fieldIsID(field)) {
continue
}

View File

@@ -37,6 +37,7 @@ export async function VersionView(props: DocumentViewServerProps) {
const localeCodesFromParams = searchParams.localeCodes
? JSON.parse(searchParams.localeCodes as string)
: null
const comparisonVersionIDFromParams: string = searchParams.compareValue as string
const modifiedOnly: boolean = searchParams.modifiedOnly === 'true'
@@ -88,7 +89,7 @@ export async function VersionView(props: DocumentViewServerProps) {
status: 'published',
})
}
} catch (error) {
} catch (_err) {
return notFound()
}
}
@@ -129,7 +130,7 @@ export async function VersionView(props: DocumentViewServerProps) {
status: 'published',
})
}
} catch (error) {
} catch (_err) {
return notFound()
}
}

View File

@@ -49,7 +49,8 @@ export const buildClientFieldSchemaMap = (args: {
if (matchedCollection.auth && !matchedCollection.auth.disableLocalStrategy) {
;(baseAuthFields[0] as TextFieldClient).label = i18n.t('general:password')
;(baseAuthFields[1] as TextFieldClient).label = i18n.t('authentication:confirmPassword')
fieldsToSet = baseAuthFields.concat(fieldsToSet)
// Place these fields _last_ to ensure they do not disrupt field paths in the field schema map
fieldsToSet = fieldsToSet.concat(baseAuthFields)
}
clientSchemaMap.set(collectionSlug, {

View File

@@ -44,7 +44,8 @@ export const buildFieldSchemaMap = (args: {
if (matchedCollection.auth && !matchedCollection.auth.disableLocalStrategy) {
;(baseAuthFields[0] as TextField).label = i18n.t('general:password')
;(baseAuthFields[1] as TextField).label = i18n.t('authentication:confirmPassword')
fieldsToSet = baseAuthFields.concat(fieldsToSet)
// Place these fields _last_ to ensure they do not disrupt field paths in the field schema map
fieldsToSet = fieldsToSet.concat(baseAuthFields)
}
schemaMap.set(collectionSlug, {

View File

@@ -31,7 +31,7 @@
}
],
"paths": {
"@payload-config": ["./test/query-presets/config.ts"],
"@payload-config": ["./test/_community/config.ts"],
"@payloadcms/admin-bar": ["./packages/admin-bar/src"],
"@payloadcms/live-preview": ["./packages/live-preview/src"],
"@payloadcms/live-preview-react": ["./packages/live-preview-react/src/index.ts"],