Skip to content

Blocks field sometimes saves null entries after deleting a block (with autosave on + blocks in admin.defaultColumns) — causes page crash #13661

@Braggedtooth

Description

@Braggedtooth

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

  1. Configure a collection with:

    • a blocks field
    • versions.drafts.autosave enabled
    • admin.defaultColumns including the blocks field key
  2. Create a document with 2–3 blocks.

  3. In the edit view:

    • Delete one block (especially after quick edits/reorders).
    • Don’t manually save; let autosave run.
  4. Open the document again or check the list view / API response:

    • The blocks array sometimes contains a null element at the deleted index.
  5. Any UI that maps over blocks or expects blockType 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

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions