-
Notifications
You must be signed in to change notification settings - Fork 2.9k
Description
Describe the Bug
When editing a document that has a blocks field (array of blocks), deleting a block sometimes results in a null item being saved into the array. This appears to happen when autosave is enabled and the blocks field is included in the collection’s admin.defaultColumns (so it renders in the list view). The null entry then causes crashes in the Admin list/detail views and/or the frontend that maps over blocks (expects objects with blockType), e.g. Cannot read properties of null (reading 'blockType')
Database: mongodb
Link to the code that reproduces this issue
https://github.com/Braggedtooth/repro-blocks-err
Reproduction
-
Configure a collection with:
- a
blocks
field versions.drafts.autosave
enabledadmin.defaultColumns
including theblocks
field key
- a
-
Create a document with 2–3 blocks.
-
In the edit view:
- Delete one block (especially after quick edits/reorders).
- Don’t manually save; let autosave run.
-
Open the document again or check the list view / API response:
- The
blocks
array sometimes contains anull
element at the deleted index.
- The
-
Any UI that maps over
blocks
or expectsblockType
throws and the page crashes.
Minimal config to reproduce
import type { CollectionConfig } from 'payload'
export const Pages: CollectionConfig = {
slug: 'pages',
admin: {
useAsTitle: 'title',
// Including blocks in defaultColumns seems to contribute to the bug
defaultColumns: ['title', 'blocks'],
},
versions: {
drafts: {
autosave: { interval: 1000 }, // also reproducible with true
},
},
fields: [
{ name: 'title', type: 'text', required: true },
{
name: 'blocks',
type: 'blocks',
blocks: [
{
slug: 'hero',
fields: [{ name: 'heading', type: 'text' }],
},
{
slug: 'content',
fields: [{ name: 'body', type: 'richText' }],
},
],
},
],
}
Expected behavior
Deleting a block should remove that item from the array (no null placeholders), and the document should autosave to a valid blocks array.
Actual behavior
Occasionally the deleted position becomes null in the persisted document:
{
"blocks": [
{ "blockType": "hero", "heading": "..." },
null,
{ "blockType": "content", "body": [/* ... */] }
]
}
This leads to:
- Admin list/detail view crashes when rendering the blocks column or preview.
Which area(s) are affected? (Select all that apply)
db-mongodb, area: ui
Environment Info
This project is configured to use pnpm
Binaries:
Node: 23.6.0
npm: 11.1.0
Yarn: N/A
pnpm: 10.5.2
Relevant Packages:
payload: 3.53.0
Operating System:
Platform: linux
Arch: x64
Version: #1 SMP PREEMPT_DYNAMIC Thu Jun 5 18:30:46 UTC 2025
Available memory (MB): 31809
Available CPU cores: 22