Skip to content

Commit 393b4a0

Browse files
authored
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 #12376 --- - To see the specific tasks where the Asana app for GitHub is being used, see below: - https://app.asana.com/0/0/1210932060696925
1 parent a94cd95 commit 393b4a0

File tree

6 files changed

+42
-11
lines changed

6 files changed

+42
-11
lines changed

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

Lines changed: 13 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -20,13 +20,13 @@ import {
2020
import {
2121
fieldIsID,
2222
fieldShouldBeLocalized,
23+
getFieldPaths,
2324
getFieldPermissions,
2425
getUniqueListBy,
2526
tabHasName,
2627
} from 'payload/shared'
2728

2829
import { diffComponents } from './fields/index.js'
29-
import { getFieldPathsModified } from './utilities/getFieldPathsModified.js'
3030

3131
export type BuildVersionFieldsArgs = {
3232
clientSchemaMap: ClientFieldSchemaMap
@@ -90,7 +90,7 @@ export const buildVersionFields = ({
9090
continue
9191
}
9292

93-
const { indexPath, path, schemaPath } = getFieldPathsModified({
93+
const { indexPath, path, schemaPath } = getFieldPaths({
9494
field,
9595
index: fieldIndex,
9696
parentIndexPath,
@@ -286,7 +286,7 @@ const buildVersionField = ({
286286
indexPath: tabIndexPath,
287287
path: tabPath,
288288
schemaPath: tabSchemaPath,
289-
} = getFieldPathsModified({
289+
} = getFieldPaths({
290290
field: tabAsField,
291291
index: tabIndex,
292292
parentIndexPath: indexPath,
@@ -322,8 +322,12 @@ const buildVersionField = ({
322322
nestingLevel: nestingLevel + 1,
323323
parentIndexPath: isNamedTab ? '' : tabIndexPath,
324324
parentIsLocalized: parentIsLocalized || tab.localized,
325-
parentPath: isNamedTab ? tabPath : path,
326-
parentSchemaPath: isNamedTab ? tabSchemaPath : parentSchemaPath,
325+
parentPath: isNamedTab ? tabPath : 'name' in field ? path : parentPath,
326+
parentSchemaPath: isNamedTab
327+
? tabSchemaPath
328+
: 'name' in field
329+
? schemaPath
330+
: parentSchemaPath,
327331
req,
328332
selectedLocales,
329333
versionFromSiblingData: 'name' in tab ? valueFrom?.[tab.name] : valueFrom,
@@ -370,8 +374,8 @@ const buildVersionField = ({
370374
nestingLevel: nestingLevel + 1,
371375
parentIndexPath: 'name' in field ? '' : indexPath,
372376
parentIsLocalized: parentIsLocalized || field.localized,
373-
parentPath: path + '.' + i,
374-
parentSchemaPath: schemaPath,
377+
parentPath: ('name' in field ? path : parentPath) + '.' + i,
378+
parentSchemaPath: 'name' in field ? schemaPath : parentSchemaPath,
375379
req,
376380
selectedLocales,
377381
versionFromSiblingData: fromRow,
@@ -469,8 +473,8 @@ const buildVersionField = ({
469473
nestingLevel: nestingLevel + 1,
470474
parentIndexPath: 'name' in field ? '' : indexPath,
471475
parentIsLocalized: parentIsLocalized || ('localized' in field && field.localized),
472-
parentPath: path + '.' + i,
473-
parentSchemaPath: schemaPath + '.' + toBlock.slug,
476+
parentPath: ('name' in field ? path : parentPath) + '.' + i,
477+
parentSchemaPath: ('name' in field ? schemaPath : parentSchemaPath) + '.' + toBlock.slug,
474478
req,
475479
selectedLocales,
476480
versionFromSiblingData: fromRow,

packages/payload/src/fields/getFieldPaths.ts

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -49,6 +49,9 @@ export function getFieldPaths({
4949
}
5050
}
5151

52+
/**
53+
* @deprecated - will be removed in 4.0. Use `getFieldPaths` instead.
54+
*/
5255
export function getFieldPathsModified({
5356
field,
5457
index,

test/versions/collections/Diff/index.ts

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -91,6 +91,15 @@ export const Diff: CollectionConfig = {
9191
name: 'textInUnnamedTab2InBlock',
9292
type: 'text',
9393
},
94+
{
95+
type: 'row',
96+
fields: [
97+
{
98+
name: 'textInRowInUnnamedTab2InBlock',
99+
type: 'text',
100+
},
101+
],
102+
},
94103
],
95104
},
96105
],

test/versions/e2e.spec.ts

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1629,6 +1629,19 @@ describe('Versions', () => {
16291629
)
16301630
})
16311631

1632+
test('correctly renders diff for text within rows within unnamed tabs within block fields', async () => {
1633+
await navigateToDiffVersionView()
1634+
1635+
const textInBlock = page.locator('[data-field-path="blocks.2.textInRowInUnnamedTab2InBlock"]')
1636+
1637+
await expect(textInBlock.locator('.html-diff__diff-old')).toHaveText(
1638+
'textInRowInUnnamedTab2InBlock',
1639+
)
1640+
await expect(textInBlock.locator('.html-diff__diff-new')).toHaveText(
1641+
'textInRowInUnnamedTab2InBlock2',
1642+
)
1643+
})
1644+
16321645
test('correctly renders diff for checkbox fields', async () => {
16331646
await navigateToDiffVersionView()
16341647

test/versions/payload-types.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1355,6 +1355,6 @@ export interface Auth {
13551355

13561356

13571357
declare module 'payload' {
1358-
// @ts-ignore
1358+
// @ts-ignore
13591359
export interface GeneratedTypes extends Config {}
1360-
}
1360+
}

test/versions/seed.ts

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -235,6 +235,7 @@ export async function seed(_payload: Payload, parallel: boolean = false) {
235235
textInNamedTab1InBlock: 'textInNamedTab1InBlock',
236236
},
237237
textInUnnamedTab2InBlock: 'textInUnnamedTab2InBlock',
238+
textInRowInUnnamedTab2InBlock: 'textInRowInUnnamedTab2InBlock',
238239
textInUnnamedTab2InBlockAccessFalse: 'textInUnnamedTab2InBlockAccessFalse',
239240
},
240241
],
@@ -372,6 +373,7 @@ export async function seed(_payload: Payload, parallel: boolean = false) {
372373
textInNamedTab1InBlock: 'textInNamedTab1InBlock2',
373374
},
374375
textInUnnamedTab2InBlock: 'textInUnnamedTab2InBlock2',
376+
textInRowInUnnamedTab2InBlock: 'textInRowInUnnamedTab2InBlock2',
375377
textInUnnamedTab2InBlockAccessFalse: 'textInUnnamedTab2InBlockAccessFalse2',
376378
},
377379
],

0 commit comments

Comments
 (0)