Repository navigation
Open
Labels
Description
Describe the Bug
When a single locale is published (a non-draft update with one locale), buildLocalizedPublishData calls mergeLocalizedData, which pairs array and block rows with the stored rows by index (L132, L184) instead of by id. Each merged row starts as a copy of that stored row (L95), so when the row at an index changes (reorder, insert, delete, block type change):
- Reordered array rows swap their other-locale values. Swap two rows and publish
en: each row now has the other row'sdevalue. This silently corrupts a locale nobody edited, with the default storage. - A new block inherits the fields of the block previously at its index. Replacing an
alphablock (a,alphaLabel) with abetablock (b) stores{ blockType: 'beta', b, a, alphaLabel }, persisted withblocksAsJSON: true.
v4 enables localizeStatus automatically, so every localized collection with drafts is affected. The merge runs after all hooks, so it can't be worked around in a hook.
Suggested fix: match the stored row by id (for blocks also by blockType), falling back to {}, like getExistingRowDoc does. With that change both tests pass:
const existingItem = existingValue?.find((row) => row?.id && row.id === newItem.id) || {}
const blockData = existingValue?.find((row) => row?.id && row.id === newBlockData.id && row.blockType === newBlockData.blockType) || {}The same bug exists in v3 (3.90.2): #18677
Link to the code that reproduces this issue
Reproduction Steps
- Clone this repo and open the
single-locale-publish-leaks-stale-row-fields-v4/directory pnpm installpnpm test:int: both tests fail
FAIL keeps the other locale of an array row with that row when rows are reordered
- Expected: [["second", "Zweite"], ["first", "Erste"]]
+ Received: [["second", "Erste"], ["first", "Zweite"]]
FAIL does not carry fields of the previous block at the same index into a new block
stored block: { blockType: 'beta', a: 'from alpha', alphaLabel: { en: 'alpha label' }, id: '…', b: 'from beta' }
Which area(s) are affected?
area: core
Environment Info
Relevant Packages:
payload: 4.0.0-beta.0
@payloadcms/db-sqlite: 4.0.0-beta.0
Node: 22.19.0, pnpm: 11.5.1, darwin arm64
Activity
fix(core): match array and block rows by id in mergeLocalizedData (pa…
peggertwizard commentedon Oct 15, 2026
Confirming this on
4.0.0-canary.37in a production site, and the same lines are unchanged in the published4.0.0-canary.39and4.0.0-beta.1builds (dist/utilities/mergeLocalizedData.js, theexistingValue?.[index]in the array branch andexistingValue[index]in the blocks branch).Our case: a non-localized
blocksfield whose text fields inside each block are localized, drafts on (solocalizeStatusis on). Moving a block to the top indeand publishing onlydeleft the publishedenwords on the old positions, so the live English page showed text on the wrong blocks. A nested array inside a block (one row per person) goes through the same branch and is affected the same way.Matching by
idin both branches, the same shape as #18680, made all 17 of our checks pass on a real Postgres database: reorder, swapping two blocks of the same type, inserting and deleting a block in the middle, and per-block locale filters. We are carrying it as a local patch until a release includes #18680. Thanks for the clear reproduction.elghaied commentedon Nov 17, 2026
This is still present in 4.0.0-beta.9. It also affects globals (
updateGlobalwith onelocale), not only collections.A minimal local-API reproduction covering both: https://github.com/elghaied/payload-v4-reproductions (
repro-1.ts). The rows are reversed with their ids kept, thenenis published alone. Thefrlabels stay at their old index:Matching rows by
id, as suggested above, fixes both for us.