-
Notifications
You must be signed in to change notification settings - Fork 2.9k
Description
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
- create a post in EN (default) with a content block
- save / publish in EN
- switch to another language
- edit the title
Which area(s) are affected? (Select all that apply)
Not sure
Environment Info
payload: 3.54.0
node: 22.13.1