Repository navigation
Description
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
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
CleanShot.2567-12-03.at.17.25.29.mp4
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
CleanShot.2567-12-03.at.17.26.25.mp4
Old behavior in Payload 2
Using the same steps for the edit page, the values is updated after saving in Payload 2.
CleanShot.2567-12-03.at.17.30.35.mp4
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
Activity
HQ92 commentedon Dec 9, 2024
I'm also getting this issue with a simple beforeChange hook that tries to clear a field value depending on a checkbox state
PeakVisionMediaKLG commentedon Dec 9, 2024
Still a problem in 3.5.0 - with Field and Collection hooks, specifically
beforeValidateandbeforeChange. A manual refresh is always needed.devdenmak commentedon Dec 10, 2024
Yes, I also have the exact same problem.
bebejane commentedon Dec 14, 2024
I have the same problem as well.
andershermansen commentedon Dec 18, 2024
This issue is still relevant with 3.8.0
PP-Tom commentedon Dec 19, 2024
+1
plumduffer commentedon Dec 22, 2024
Also having this issue
zabatonni commentedon Jan 2, 2025
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.
fix(ui): properly reflects hook changes in ui (#10268)
jmikrut commentedon Jan 3, 2025
Hi all, this will be fixed in the next release!
github-actions commentedon Jan 5, 2025
This issue has been automatically locked.
Please open a new issue if this issue persists with any additional detail.