Skip to content

Commit

Permalink
fix(ui): dedupes custom id fields (#9050)
Browse files Browse the repository at this point in the history
Setting a custom `id` field within unnamed fields causes duplicative ID
fields to be appear in the client config. When a top-level `id` field is
detected in your config, Payload uses that instead of injecting its
default field. But when nested within unnamed fields, such as an unnamed
tab, these custom `id` fields were not being found, causing the default
field to be duplicately rendered into tables columns, etc.
  • Loading branch information
jacobsfletch authored Nov 6, 2024
1 parent becf56d commit 4b4ecb3
Showing 1 changed file with 2 additions and 2 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ import type {
TabsFieldClient,
} from 'payload'

import { deepCopyObjectSimple, MissingEditorProp } from 'payload'
import { deepCopyObjectSimple, flattenTopLevelFields, MissingEditorProp } from 'payload'
import { fieldAffectsData, fieldIsPresentationalOnly } from 'payload/shared'

import { getComponent } from './getComponent.js'
Expand Down Expand Up @@ -579,7 +579,7 @@ export const createClientFields = ({
}
}

const hasID = newClientFields.findIndex((f) => fieldAffectsData(f) && f.name === 'id') > -1
const hasID = flattenTopLevelFields(fields).some((f) => fieldAffectsData(f) && f.name === 'id')

if (!disableAddingID && !hasID) {
newClientFields.push({
Expand Down

0 comments on commit 4b4ecb3

Please sign in to comment.