Admin UI doesn't update values changed in hooks
Describe the Bug
When saving a document, the admin UI doesn't update the form state with new values from the server.
This causes it to be stale if there's a beforeChange field hook that changes the value.
This only happens in the edit page. In the create page, the changed field gets updated correctly. I found this issue while migrating my project from Payload 2 that depended on the fields being updated.
Previously, I thought that #9573 would fix this, but it seems that PR only merges the error states and not values, and only does so when autosave is disabled. If this is intended, could it be made an option to also update server values as well, or allow overriding the form submit behavior?
Currently I'm reloading the whole page on save, but that's very slow so it's not ideal for me.
Link to the code that reproduces this issue
https://github.com/suphon-t/payload/blob/reproduce/admin-ui-stale-fields/test/_community/e2e.spec.ts
Reproduction Steps
In these steps, I have a posts collection with title and slug field.
The slug field has a beforeChange hook that takes the value from title, and replaces spaces with -.
Working: When saving from the create page, the form gets updated with server values
- Go to the create post page
- Fill the post title, and click publish
- The slug field gets a value computed from the title
https://github.com/user-attachments/assets/a1d3644b-6312-4831-bf3e-aae5821b4862
Broken: When saving from the edit page, the form doesn't get updated with the new values from the server
- Create a post with a title and go to the edit page
- Change the post title to something else, and save
- The slug field stays the same
- Refresh the page
- The slug field is changed to the new value
https://github.com/user-attachments/assets/fccb86a8-8863-4be2-a4ad-8241f5dd6118
Old behavior in Payload 2
Using the same steps for the edit page, the values is updated after saving in Payload 2.
https://github.com/user-attachments/assets/3537b82c-0998-48dc-a3c0-73a2c24263e6
https://github.com/suphon-t/payload/blob/reproduce/admin-ui-stale-fields-2.x/test/_community/e2e.spec.ts
Which area(s) are affected? (Select all that apply)
area: ui
Environment Info
Binaries:
Node: 20.10.0
npm: 10.2.3
Yarn: 4.0.2
pnpm: 9.14.4
Relevant Packages:
payload: 3.2.2
next: 15.0.3
@payloadcms/db-postgres: 3.2.2
@payloadcms/email-nodemailer: 3.2.2
@payloadcms/graphql: 3.2.2
@payloadcms/next/utilities: 3.2.2
@payloadcms/payload-cloud: 3.2.2
@payloadcms/plugin-cloud-storage: 3.2.2
@payloadcms/plugin-seo: 3.2.2
@payloadcms/richtext-lexical: 3.2.2
@payloadcms/storage-s3: 3.2.2
@payloadcms/translations: 3.2.2
@payloadcms/ui/shared: 3.2.2
react: 19.0.0-rc-66855b96-20241106
react-dom: 19.0.0-rc-66855b96-20241106
Operating System:
Platform: darwin
Arch: arm64
Version: Darwin Kernel Version 24.2.0: Sun Nov 3 20:57:51 PST 2024; root:xnu-11215.60.405~54/RELEASE_ARM64_T8112
Available memory (MB): 16384
Available CPU cores: 8
I'm also getting this issue with a simple beforeChange hook that tries to clear a field value depending on a checkbox state
Still a problem in 3.5.0 - with Field and Collection hooks, specifically beforeValidate and beforeChange. A manual refresh is always needed.
Yes, I also have the exact same problem.
I have the same problem as well.
This issue is still relevant with 3.8.0
+1
Also having this issue
When using autosave:false, sometimes it doesn't refresh as well. When combined with array field, things get even worse and it removes fields from the UI randomly.
Hi all, this will be fixed in the next release!
This issue has been automatically locked. Please open a new issue if this issue persists with any additional detail.