Skip to content

previousValue, previousSiblingDoc not available in afterChange field hook in Blocks/Arrays in Blocks #14151

@nvys

Description

@nvys

Describe the Bug

• In Blocks fields: afterChange field hooks do not receive previousValue (it does receive previousSiblingDoc though).
• In Array fields inside Blocks fields: afterChange field hooks do not receive both previousValue and previousSiblingDoc.

Note: beforeChange hooks work fine and receive the correct values for previousValue and previousSiblingDoc in both cases.

==== In Block: afterChange ====
value: main-block-text-CHANGED

previousValue: undefined

previousSiblingDoc: {
  id: '68e929f99d9d6fcc034e23c7',
  main: 'main-block-text',
  sibling: 'sibling-block-text',
  blockName: null,
  testarray: [
    {
      id: '68e92b63fa2a776341dc0708',
      mainInArray: 'main-array-text',
      siblingInArray: 'sibling-array-text'
    }
  ],
  blockType: 'testblock'
}
==== In Array inside Block: afterChange ====
value: main-array-text-CHANGED

previousValue: undefined
previousSiblingDoc {}

Link to the code that reproduces this issue

https://github.com/nvys/payload-afterchange-bug

Reproduction Steps

• Fresh Payload install with pnpx create-payload-app@latest
• SQLite DB
• Create sample Test collection with a blocks field
• Create a field with an afterChange field hook, pass the hook previousValue and log it
• Create a document in the collection, type some text in the field and save
• Make a change in the field and save
• previousValue is logged as undefined

--- Then for array fields inside blocks:
• Create an array field with a text field inside the block
• Add an afterChange field hook to the text field, pass the hook previousValue and previousSiblingDoc and log them
• Create a document in the collection, add an item to the array and save
• Make a change in the array and save
• previousValue is logged as undefined
• previousSiblingDoc is logged as undefined

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

area: core

Environment Info

Binaries:
  Node: 23.7.0
  npm: 11.1.0
  Yarn: N/A
  pnpm: 10.2.1
Relevant Packages:
  payload: 3.59.1
  next: 15.4.4
  @payloadcms/db-sqlite: 3.59.1
  @payloadcms/drizzle: 3.59.1
  @payloadcms/email-nodemailer: 3.59.1
  @payloadcms/graphql: 3.59.1
  @payloadcms/next/utilities: 3.59.1
  @payloadcms/payload-cloud: 3.59.1
  @payloadcms/richtext-lexical: 3.59.1
  @payloadcms/translations: 3.59.1
  @payloadcms/ui/shared: 3.59.1
  react: 19.1.0
  react-dom: 19.1.0
Operating System:
  Platform: linux
  Arch: x64
  Version: #1 SMP PREEMPT_DYNAMIC Thu Jun  5 18:30:46 UTC 2025
  Available memory (MB): 15959
  Available CPU cores: 16

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