Skip to content

bug: v4 single-locale publish pairs block/array rows by index, not id #18678

Open

Description

@jhb-dev

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):

  1. Reordered array rows swap their other-locale values. Swap two rows and publish en: each row now has the other row's de value. This silently corrupts a locale nobody edited, with the default storage.
  2. A new block inherits the fields of the block previously at its index. Replacing an alpha block (a, alphaLabel) with a beta block (b) stores { blockType: 'beta', b, a, alphaLabel }, persisted with blocksAsJSON: 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

https://github.com/jhb-software/payload-issue-reproductions/tree/main/single-locale-publish-leaks-stale-row-fields-v4/

Reproduction Steps

  1. Clone this repo and open the single-locale-publish-leaks-stale-row-fields-v4/ directory
  2. pnpm install
  3. pnpm 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

  1. peggertwizard commented on Oct 15, 2026

    @peggertwizard

    Confirming this on 4.0.0-canary.37 in a production site, and the same lines are unchanged in the published 4.0.0-canary.39 and 4.0.0-beta.1 builds (dist/utilities/mergeLocalizedData.js, the existingValue?.[index] in the array branch and existingValue[index] in the blocks branch).

    Our case: a non-localized blocks field whose text fields inside each block are localized, drafts on (so localizeStatus is on). Moving a block to the top in de and publishing only de left the published en words 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 id in 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.

  2. elghaied commented on Nov 17, 2026

    @elghaied

    This is still present in 4.0.0-beta.9. It also affects globals (updateGlobal with one locale), 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, then en is published alone. The fr labels stay at their old index:

    [collection] expected fr: e4ec:c-fr, e4eb:b-fr, e4ea:a-fr
    [collection] observed fr: e4ec:a-fr, e4eb:b-fr, e4ea:c-fr
    [global]     expected fr: e4ef:c-fr, e4ee:b-fr, e4ed:a-fr
    [global]     observed fr: e4ef:a-fr, e4ee:b-fr, e4ed:c-fr
    

    Matching rows by id, as suggested above, fixes both for us.

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

Metadata

Metadata

Assignees

No one assigned

    Labels

    Bugarea: corecreated-by: Contributor

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions