diff --git a/packages/payload/src/utilities/traverseFields.ts b/packages/payload/src/utilities/traverseFields.ts index 9e7fb8b1d..766accef3 100644 --- a/packages/payload/src/utilities/traverseFields.ts +++ b/packages/payload/src/utilities/traverseFields.ts @@ -416,20 +416,11 @@ export const traverseFields = ({ }) ) { if (Array.isArray(currentRef)) { - return - } - - for (const key in currentRef as Record) { - const localeData = currentRef[key as keyof typeof currentRef] - if (!Array.isArray(localeData)) { - continue - } - traverseArrayOrBlocksField({ callback, callbackStack, config, - data: localeData, + data: currentRef, field, fillEmpty, leavesFirst, @@ -437,6 +428,26 @@ export const traverseFields = ({ parentPath, parentRef: currentParentRef, }) + } else { + for (const key in currentRef as Record) { + const localeData = currentRef[key as keyof typeof currentRef] + if (!Array.isArray(localeData)) { + continue + } + + traverseArrayOrBlocksField({ + callback, + callbackStack, + config, + data: localeData, + field, + fillEmpty, + leavesFirst, + parentIsLocalized: true, + parentPath, + parentRef: currentParentRef, + }) + } } } else if (Array.isArray(currentRef)) { traverseArrayOrBlocksField({ diff --git a/test/localization/collections/Blocks/index.ts b/test/localization/collections/Blocks/index.ts index 10cd389b0..687bea5e2 100644 --- a/test/localization/collections/Blocks/index.ts +++ b/test/localization/collections/Blocks/index.ts @@ -4,7 +4,30 @@ export const blocksCollectionSlug = 'blocks-fields' export const BlocksCollection: CollectionConfig = { slug: blocksCollectionSlug, + versions: { drafts: true }, fields: [ + { + type: 'tabs', + tabs: [ + { + label: 'Tab', + fields: [ + { + name: 'tabContent', + label: 'Content', + type: 'blocks', + localized: true, + blocks: [ + { + slug: 'blockInsideTab', + fields: [{ type: 'text', name: 'text' }], + }, + ], + }, + ], + }, + ], + }, { name: 'content', label: 'Content', diff --git a/test/localization/int.spec.ts b/test/localization/int.spec.ts index 175ed1f00..9ca29c336 100644 --- a/test/localization/int.spec.ts +++ b/test/localization/int.spec.ts @@ -2903,7 +2903,7 @@ describe('Localization', () => { }) const req = await createLocalReq({ user }, payload) - + global.d = true const res = (await copyDataFromLocaleHandler({ fromLocale: 'en', req, @@ -2915,6 +2915,36 @@ describe('Localization', () => { expect(res.content?.[0]?.content?.[0]?.text).toBe('some-text') }) + it('should copy block inside tab to locale', async () => { + // This was previously an e2e test but it was migrated to int + // because at the moment only int tests run in Postgres in CI, + // and that's where the bug occurs. + const doc = await payload.create({ + collection: 'blocks-fields', + locale: 'en', + data: { + tabContent: [ + { + blockType: 'blockInsideTab', + text: 'some-text', + }, + ], + }, + }) + + const req = await createLocalReq({ user }, payload) + global.d = true + const res = (await copyDataFromLocaleHandler({ + fromLocale: 'en', + req, + toLocale: 'pt', + docID: doc.id, + collectionSlug: 'blocks-fields', + })) as BlocksField + + expect(res.tabContent?.[0]?.text).toBe('some-text') + }) + it('should copy localized nested to arrays', async () => { const doc = await payload.create({ collection: 'nested', diff --git a/test/localization/payload-types.ts b/test/localization/payload-types.ts index 54b0d0903..dead59bd4 100644 --- a/test/localization/payload-types.ts +++ b/test/localization/payload-types.ts @@ -192,6 +192,14 @@ export interface RichText { */ export interface BlocksField { id: string; + tabContent?: + | { + text?: string | null; + id?: string | null; + blockName?: string | null; + blockType: 'blockInsideTab'; + }[] + | null; content?: | { content?: @@ -217,6 +225,7 @@ export interface BlocksField { | null; updatedAt: string; createdAt: string; + _status?: ('draft' | 'published') | null; } /** * This interface was referenced by `Config`'s JSON-Schema @@ -877,6 +886,17 @@ export interface RichTextSelect { * via the `definition` "blocks-fields_select". */ export interface BlocksFieldsSelect { + tabContent?: + | T + | { + blockInsideTab?: + | T + | { + text?: T; + id?: T; + blockName?: T; + }; + }; content?: | T | { @@ -910,6 +930,7 @@ export interface BlocksFieldsSelect { }; updatedAt?: T; createdAt?: T; + _status?: T; } /** * This interface was referenced by `Config`'s JSON-Schema @@ -1499,6 +1520,6 @@ export interface Auth { declare module 'payload' { - // @ts-ignore + // @ts-ignore export interface GeneratedTypes extends Config {} -} +} \ No newline at end of file