payloadcms / payload

Payload is the open-source, fullstack Next.js framework, giving you instant backend superpowers. Get a full TypeScript backend and admin panel instantly. Use Payload as a headless CMS or for building powerful applications.
https://payloadcms.com
MIT License
27.66k stars 1.72k forks source link

`beforeValidate` hook runs, but doesn't update UI during `update` operation #9423

Open yulolimum opened 10 hours ago

yulolimum commented 10 hours ago

Describe the Bug

Hello, this originally was observed with the example app's "slug" field. However this was reproduced on a fresh payload app.

Setting up a beforeValidate hook to transform a field value works on both create and update. But...

During create the transformation is immediately available in the UI. I suspect due to the page path going from /create -> /{resource_id}

During update the transformation runs, butis not reflected in the UI.

Here is a video demoing the issue:

https://github.com/user-attachments/assets/e8f0d17a-e8ed-441e-ad7a-2ff96cb1612d

Link to the code that reproduces this issue

https://github.com/yulolimum/tmp-payload-before-validate-repro

Reproduction Steps

  1. Clone Repo

    git clone git@github.com:yulolimum/tmp-payload-before-validate-repro.git
  2. Install Deps

    cd tmp-payload-before-validate-repro
    yarn
  3. Start Dev Server

    yarn dev
  4. Login

    • user: repro@payload.com
    • pass: repro
  5. Create a New User

    • After filling out the field "Demo Field" with any text and clicking "Save", the field should change to "you should see this".
  6. Update the User

    • Change the "Demo Field" to any text and click "Save". Observe - field remains with the same text you typed.
  7. Refresh the Page

    • After refreshing the page, the field should change to "you should see this".

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

area: core

Environment Info

Binaries:
  Node: 22.11.0
  npm: 10.9.0
  Yarn: 4.5.2
  pnpm: N/A
Relevant Packages:
  payload: 3.0.2
  next: 15.0.3
  @payloadcms/db-mongodb: 3.0.2
  @payloadcms/email-nodemailer: 3.0.2
  @payloadcms/graphql: 3.0.2
  @payloadcms/next/utilities: 3.0.2
  @payloadcms/plugin-seo: 3.0.2
  @payloadcms/richtext-lexical: 3.0.2
  @payloadcms/translations: 3.0.2
  @payloadcms/ui/shared: 3.0.2
  react: 19.0.0-rc-65a56d0e-20241020
  react-dom: 19.0.0-rc-65a56d0e-20241020
Operating System:
  Platform: darwin
  Arch: arm64
  Version: Darwin Kernel Version 23.1.0: Mon Oct  9 21:27:24 PDT 2023; root:xnu-10002.41.9~6/RELEASE_ARM64_T6000
  Available memory (MB): 65536
  Available CPU cores: 10