payload icon indicating copy to clipboard operation
payload copied to clipboard

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

Open yulolimum opened this issue 1 year ago • 3 comments

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:

  • In the first part, you will see the field changes correctly during create.
  • In the second part (update), you will see the field will only change after a page refresh.

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 [email protected]: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

  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

yulolimum avatar Nov 22 '24 02:11 yulolimum

I'm also having this issue. in 3.1.0, also with a custom slug field being formatted in a beforeValidate hook. I've used the same exact function in dozens of projects, without issue before.

HarleySalas avatar Nov 22 '24 21:11 HarleySalas

I can verify that I have the same problem on 3.1.0.

PeakVisionMediaKLG avatar Nov 23 '24 01:11 PeakVisionMediaKLG

I've gone back and determined it started occurring in beta 128.

rilrom avatar Nov 23 '24 02:11 rilrom

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

github-actions[bot] avatar Nov 29 '24 04:11 github-actions[bot]

🚀 This is included in version v3.2.2

github-actions[bot] avatar Nov 29 '24 18:11 github-actions[bot]