fix(next): no client field found error when accessing version view in some configurations (#13339)

This PR fixes some incorrect field paths handling (=> should not pass
path and schema paths that contain index paths down to sub-fields
outside of the indexPath property) when building the version fields.

Fixes https://github.com/payloadcms/payload/issues/12376

---
- To see the specific tasks where the Asana app for GitHub is being
used, see below:
  - https://app.asana.com/0/0/1210932060696925
This commit is contained in:
Alessio Gravili
2025-08-21 07:04:55 -07:00
committed by GitHub
parent a94cd95b90
commit 393b4a0929
6 changed files with 42 additions and 11 deletions

View File

@@ -20,13 +20,13 @@ import {
import {
fieldIsID,
fieldShouldBeLocalized,
getFieldPaths,
getFieldPermissions,
getUniqueListBy,
tabHasName,
} from 'payload/shared'
import { diffComponents } from './fields/index.js'
import { getFieldPathsModified } from './utilities/getFieldPathsModified.js'
export type BuildVersionFieldsArgs = {
clientSchemaMap: ClientFieldSchemaMap
@@ -90,7 +90,7 @@ export const buildVersionFields = ({
continue
}
const { indexPath, path, schemaPath } = getFieldPathsModified({
const { indexPath, path, schemaPath } = getFieldPaths({
field,
index: fieldIndex,
parentIndexPath,
@@ -286,7 +286,7 @@ const buildVersionField = ({
indexPath: tabIndexPath,
path: tabPath,
schemaPath: tabSchemaPath,
} = getFieldPathsModified({
} = getFieldPaths({
field: tabAsField,
index: tabIndex,
parentIndexPath: indexPath,
@@ -322,8 +322,12 @@ const buildVersionField = ({
nestingLevel: nestingLevel + 1,
parentIndexPath: isNamedTab ? '' : tabIndexPath,
parentIsLocalized: parentIsLocalized || tab.localized,
parentPath: isNamedTab ? tabPath : path,
parentSchemaPath: isNamedTab ? tabSchemaPath : parentSchemaPath,
parentPath: isNamedTab ? tabPath : 'name' in field ? path : parentPath,
parentSchemaPath: isNamedTab
? tabSchemaPath
: 'name' in field
? schemaPath
: parentSchemaPath,
req,
selectedLocales,
versionFromSiblingData: 'name' in tab ? valueFrom?.[tab.name] : valueFrom,
@@ -370,8 +374,8 @@ const buildVersionField = ({
nestingLevel: nestingLevel + 1,
parentIndexPath: 'name' in field ? '' : indexPath,
parentIsLocalized: parentIsLocalized || field.localized,
parentPath: path + '.' + i,
parentSchemaPath: schemaPath,
parentPath: ('name' in field ? path : parentPath) + '.' + i,
parentSchemaPath: 'name' in field ? schemaPath : parentSchemaPath,
req,
selectedLocales,
versionFromSiblingData: fromRow,
@@ -469,8 +473,8 @@ const buildVersionField = ({
nestingLevel: nestingLevel + 1,
parentIndexPath: 'name' in field ? '' : indexPath,
parentIsLocalized: parentIsLocalized || ('localized' in field && field.localized),
parentPath: path + '.' + i,
parentSchemaPath: schemaPath + '.' + toBlock.slug,
parentPath: ('name' in field ? path : parentPath) + '.' + i,
parentSchemaPath: ('name' in field ? schemaPath : parentSchemaPath) + '.' + toBlock.slug,
req,
selectedLocales,
versionFromSiblingData: fromRow,

View File

@@ -49,6 +49,9 @@ export function getFieldPaths({
}
}
/**
* @deprecated - will be removed in 4.0. Use `getFieldPaths` instead.
*/
export function getFieldPathsModified({
field,
index,

View File

@@ -91,6 +91,15 @@ export const Diff: CollectionConfig = {
name: 'textInUnnamedTab2InBlock',
type: 'text',
},
{
type: 'row',
fields: [
{
name: 'textInRowInUnnamedTab2InBlock',
type: 'text',
},
],
},
],
},
],

View File

@@ -1629,6 +1629,19 @@ describe('Versions', () => {
)
})
test('correctly renders diff for text within rows within unnamed tabs within block fields', async () => {
await navigateToDiffVersionView()
const textInBlock = page.locator('[data-field-path="blocks.2.textInRowInUnnamedTab2InBlock"]')
await expect(textInBlock.locator('.html-diff__diff-old')).toHaveText(
'textInRowInUnnamedTab2InBlock',
)
await expect(textInBlock.locator('.html-diff__diff-new')).toHaveText(
'textInRowInUnnamedTab2InBlock2',
)
})
test('correctly renders diff for checkbox fields', async () => {
await navigateToDiffVersionView()

View File

@@ -235,6 +235,7 @@ export async function seed(_payload: Payload, parallel: boolean = false) {
textInNamedTab1InBlock: 'textInNamedTab1InBlock',
},
textInUnnamedTab2InBlock: 'textInUnnamedTab2InBlock',
textInRowInUnnamedTab2InBlock: 'textInRowInUnnamedTab2InBlock',
textInUnnamedTab2InBlockAccessFalse: 'textInUnnamedTab2InBlockAccessFalse',
},
],
@@ -372,6 +373,7 @@ export async function seed(_payload: Payload, parallel: boolean = false) {
textInNamedTab1InBlock: 'textInNamedTab1InBlock2',
},
textInUnnamedTab2InBlock: 'textInUnnamedTab2InBlock2',
textInRowInUnnamedTab2InBlock: 'textInRowInUnnamedTab2InBlock2',
textInUnnamedTab2InBlockAccessFalse: 'textInUnnamedTab2InBlockAccessFalse2',
},
],