Skip to content

[Data Loss] Value not set in bulk actions in the beforeValidate hook #10923

Closed

Description

@PP-Tom

Describe the Bug

This can cause loss of data when using bulk actions. In this example I'm using slug

{
  name: 'slug',
  type: 'text',
  unique: true,
  required: true,
  hooks: {
    beforeValidate: [
      ({ value, siblingData }) => {
        if (typeof value === 'string') {
          return slugify(value, { lower: true, trim: true })
        } else if (typeof siblingData?.title === 'string') {
          return slugify(siblingData.title, { lower: true, trim: true })
        }

        return value
      },
    ],
  },
}

Link to the code that reproduces this issue

https://github.com/PP-Tom/payload-bugs

Reproduction Steps

  1. Go to Projects
  2. Seed Data
  3. Publish the Project
  4. Go back to the Project collection list view
  5. Change locale and check the box in the list
  6. Press Publish
  7. Value is lost and the title is taken

OR

  1. Go to Projects
  2. Seed Data
  3. Publish the Project
  4. Make a change to the title
  5. Go back to list view
  6. Check the box in the list
  7. Press Publish
  8. Value is lost and the title is taken

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

Not sure

Environment Info

Payload: 3.20.0
NodeJS: 22
NextJS: 15.1.6

Activity

  1. added
    status: needs-triage
    validate-reproduction
    on Feb 1, 2025
  2. removed
    validate-reproduction
    on Feb 1, 2025
  3. changed the title [-]Value not set in bulk actions in the beforeValidate hook[/-] [+][Data Loss] Value not set in bulk actions in the beforeValidate hook[/+] on Feb 4, 2025
  4. KoenRijpstra commented on Feb 25, 2025

    @KoenRijpstra

    @jmikrut Any updates on this? I’m facing the same issue and now need to update 175 doc pages.

    Binaries:
    Node: 23.5.0
    npm: 10.9.2
    Yarn: N/A
    pnpm: 9.13.0
    Relevant Packages:
    payload: 3.24.0
    next: 15.1.7
    @payloadcms/graphql: 3.24.0
    @payloadcms/live-preview: 3.24.0
    @payloadcms/live-preview-react: 3.24.0
    @payloadcms/next/utilities: 3.24.0
    @payloadcms/plugin-cloud-storage: 3.24.0
    @payloadcms/plugin-form-builder: 3.24.0
    @payloadcms/plugin-nested-docs: 3.24.0
    @payloadcms/plugin-redirects: 3.24.0
    @payloadcms/plugin-search: 3.24.0
    @payloadcms/plugin-seo: 3.24.0
    @payloadcms/richtext-lexical: 3.24.0
    @payloadcms/storage-vercel-blob: 3.24.0
    @payloadcms/translations: 3.24.0
    @payloadcms/ui/shared: 3.24.0
    react: 19.0.0
    react-dom: 19.0.0

  5. KoenRijpstra commented on Feb 25, 2025

    @KoenRijpstra

    @AlessioGr Fields with a beforeValidate hook appear to be removed from the data passed to the beforeValidate function. When I remove the hook from a field and log the data in another hook, the field’s data is present. However, when I add the hook back, the data for that field disappears.

    Think it is related to this PR: #10666

  6. removed
    status: needs-triage
    on Feb 25, 2025
  7. github-actions commented on Mar 4, 2025

    @github-actions
    Contributor

    🚀 This is included in version v3.26.0

  8. github-actions commented on Mar 12, 2025

    @github-actions
    Contributor

    This issue has been automatically locked.
    Please open a new issue if this issue persists with any additional detail.

  9. locked as resolved and limited conversation to collaborators on Mar 12, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

Type

No type

Projects

No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions