Skip to content

Localized blocks with fallback get saved as [null] instead of null in versioned collections #13663

@AZ-Geneon

Description

@AZ-Geneon

Describe the Bug

When editing a versioned document with a localized "blocks"-field, the block is getting a wrong value when being persisted in the database when using the "fallback to default language"-checkbox. This can happen to the "posts" or the "_posts_versions" table in this example.
The value looks like this:
"es": [ null ], "de": [ ] instead of "es": null, "de": [ ]

And we're getting the following error in the log:

[13:09:38] ERROR: There was an error while saving a version for the Post with ID 68b6d037f2183a5d9dbd4bc8. err: { "type": "TypeError", "message": "Cannot read properties of null (reading 'blockType')", "stack": TypeError: Cannot read properties of null (reading 'blockType') at E:\test\payload-versioning-localized-blocks-bug\.next\server\chunks\packages_db-mongodb_src_6253a22b._.js:1499:95

The fallback-checkbox also gets removed when the error happens. In my case, it sometimes gets replaced by the actual value of the default-language block.

The easiest way to reproduce is to use autosave but it happens even with autosave disabled (but not as easy to reproduce)

Link to the code that reproduces this issue

https://github.com/AZ-Geneon/payload-versioning-localized-blocks-bug

Reproduction Steps

  1. create a post in EN (default) with a content block
  2. save / publish in EN
  3. switch to another language
  4. edit the title

Which area(s) are affected? (Select all that apply)

Not sure

Environment Info

payload: 3.54.0
node: 22.13.1

Metadata

Metadata

Assignees

No one assigned

    Labels

    status: needs-triagePossible bug which hasn't been reproduced yet

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions