Skip to content

fix: Empty localized blocks when duplicating document (#15847)#16560

Open
deepshekhardas wants to merge 3 commits intopayloadcms:mainfrom
deepshekhardas:fix/15847-empty-value-of-localized-fields-when-duplicating
Open

fix: Empty localized blocks when duplicating document (#15847)#16560
deepshekhardas wants to merge 3 commits intopayloadcms:mainfrom
deepshekhardas:fix/15847-empty-value-of-localized-fields-when-duplicating

Conversation

@deepshekhardas
Copy link
Copy Markdown
Contributor

Summary

When duplicating a single locale, any blocks fields with localization enabled are empty in the duplicated document. This prevents editors from creating locale-specific copies of a document.

Root Cause

The filterDataToSelectedLocales utility was iterating through all blockReferences but never finding the matching blockType because:

  1. The for-loop never broke after finding a match
  2. It was comparing all references against the data's blockType, but only the first iteration's result was used

Fix

Changed the block lookup logic to use Array.find() instead of a for-loop, which:

  1. Properly returns the first matching block reference
  2. Correctly matches blockType against block references (either slug strings or Block objects)

Changes

  • packages/payload/src/utilities/filterDataToSelectedLocales.ts - Fixed block lookup logic
  • packages/payload/src/utilities/filterDataToSelectedLocales.spec.ts - Added test cases for localized blocks

Testing

  • Create collection with localized blocks field and title field
  • Switch to DE locale, create document with blocks, publish
  • Use "Duplicate selected locale" action
  • Verify blocks are preserved in duplicated document

Related Issues

Fixes #15847

pevecj and others added 3 commits March 4, 2026 21:30
…y duplicated during selected locale duplication
When duplicating a localized blocks field, the block lookup was iterating
through all blockReferences but never finding the matching blockType.

Fixed the logic to use Array.find() instead of a for-loop to properly
match blockType against block references.

Added test cases for localized blocks with both simple and localized
child fields to prevent regression.
@github-actions
Copy link
Copy Markdown
Contributor

github-actions Bot commented May 9, 2026

Pull Request titles must follow the Conventional Commits specification and have valid scopes.

The subject "Empty localized blocks when duplicating document (#15847)" found in the pull request title "fix: Empty localized blocks when duplicating document (#15847)"
didn't match the configured pattern. Please ensure that the subject
doesn't start with an uppercase character.

feat(ui): add Button component
^    ^    ^
|    |    |__ Subject
|    |_______ Scope
|____________ Type

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Bug: Duplicating a selected locale copies empty values for localized block fields

1 participant