Skip to content

reordering blocks using a beforeChange hook mixes up block types in the admin UI and can lead to corrupted documents #12368

@ioExpander

Description

@ioExpander

Describe the Bug

I have a use case where I need to reorder blocks based on dates using a beforeChange hook.
However when reordering the blocks the UI seem to mix up blocks types and contents.

In the reproduction repo I have setup a very simple Pages example that sorts blocks in descending order and can reproduce the main issue.

In a more complex example I have managed to corrupt blocks data after the third save with an incorrect state in the admin UI.

Link to the code that reproduces this issue

https://github.com/ioExpander/payload-issue-blocksReorder.git

Reproduction Steps

pnpm install && pnpm dev
create admin account
create and save an empty page, then follow instructions to add blocks
Add block one, title "one" order "1", save the Page document
Add block two, title "two" order "2", save the page document

The blocks are saved but the admin UI is confused between blocks types (ie : block 01 is of type one but has block two contents)

Image

Adding block `three, title "three" order "3" etc will continue producing the same bug.

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

area: ui

Environment Info

Binaries:
  Node: 20.19.0
  npm: 10.8.2
  Yarn: 1.22.22
  pnpm: 10.6.4
Relevant Packages:
  payload: 3.33.0
  next: 15.3.0
  @payloadcms/email-nodemailer: 3.33.0
  @payloadcms/graphql: 3.33.0
  @payloadcms/next/utilities: 3.33.0
  @payloadcms/payload-cloud: 3.33.0
  @payloadcms/richtext-lexical: 3.33.0
  @payloadcms/translations: 3.33.0
  @payloadcms/ui/shared: 3.33.0
  react: 19.1.0
  react-dom: 19.1.0
Operating System:
  Platform: linux
  Arch: x64
  Version: #32~22.04.1-Ubuntu SMP Thu Apr  3 20:26:27 UTC 2025
  Available memory (MB): 7938
  Available CPU cores: 2

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