Skip to content

Admin UI doesn't update values changed in hooks #9691

Closed

Description

@suphon-t

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

  1. Go to the create post page
  2. Fill the post title, and click publish
  3. 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

  1. Create a post with a title and go to the edit page
  2. Change the post title to something else, and save
  3. The slug field stays the same
  4. Refresh the page
  5. 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

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

Activity

  1. added
    status: needs-triage
    validate-reproduction
    on Dec 3, 2024
  2. removed
    validate-reproduction
    on Dec 3, 2024
  3. HQ92 commented on Dec 9, 2024

    @HQ92

    I'm also getting this issue with a simple beforeChange hook that tries to clear a field value depending on a checkbox state

  4. PeakVisionMediaKLG commented on Dec 9, 2024

    @PeakVisionMediaKLG

    Still a problem in 3.5.0 - with Field and Collection hooks, specifically beforeValidate and beforeChange. A manual refresh is always needed.

  5. devdenmak commented on Dec 10, 2024

    @devdenmak

    Yes, I also have the exact same problem.

  6. bebejane commented on Dec 14, 2024

    @bebejane

    I have the same problem as well.

  7. andershermansen commented on Dec 18, 2024

    @andershermansen
    Contributor

    This issue is still relevant with 3.8.0

  8. PP-Tom commented on Dec 19, 2024

    @PP-Tom

    +1

  9. plumduffer commented on Dec 22, 2024

    @plumduffer

    Also having this issue

  10. self-assigned this
    on Dec 30, 2024
  11. removed
    status: needs-triage
    on Dec 30, 2024
  12. zabatonni commented on Jan 2, 2025

    @zabatonni

    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.

  13. jmikrut commented on Jan 3, 2025

    @jmikrut
    Member

    Hi all, this will be fixed in the next release!

  14. github-actions commented on Jan 5, 2025

    @github-actions
    Contributor

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

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

Metadata

Metadata

Assignees

Labels

No labels
No labels

Type

No type

Projects

No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions