Skip to content

Live Preview: beforeChange hook not reflected in admin ui #10536

Closed

Description

@bebejane

Describe the Bug

When applying a beforeChange hook to a collection, changes to the record does not reflect in the ui in Live Preview view.

This was fixed for the Edit view in #10268 but persists in Live Preview mode.

Also, updates of the data in the hook is not received in the the admin.livePreview defined function for generating the preview url. Since the pathname to the page depends on the slug field, it's not possible to construct the correct pathname upon changing the slug.

Also, i'm not sure if this is a bug or intended but when autosave:true is defined in the collection config, changes in hooks are not reflected at all, both in Edit and Live Preview mode.

Link to the code that reproduces this issue

https://github.com/bebejane/payload-hook-bug

Reproduction Steps

  1. Clone
  2. pnpm i
  3. pnpm dev
  4. Go to /admin and create the first user
  5. Go to Posts collection and add a post
  6. See the slug field change upon changing title when saving in edit view
  7. Swich to Live Preview mode
  8. Changes do not update in ui when saving

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

area: ui

Environment Info

Binaries:
  Node: 18.20.4
  npm: 10.7.0
  Yarn: 1.22.22
  pnpm: 9.15.0
Relevant Packages:
  payload: 3.16.0
  next: 15.1.4
  @payloadcms/email-nodemailer: 3.16.0
  @payloadcms/graphql: 3.16.0
  @payloadcms/live-preview: 3.16.0
  @payloadcms/next/utilities: 3.16.0
  @payloadcms/payload-cloud: 3.16.0
  @payloadcms/richtext-lexical: 3.16.0
  @payloadcms/translations: 3.16.0
  @payloadcms/ui/shared: 3.16.0
  react: 19.0.0
  react-dom: 19.0.0
Operating System:
  Platform: darwin
  Arch: arm64
  Version: Darwin Kernel Version 22.5.0: Mon Apr 24 20:52:24 PDT 2023; root:xnu-8796.121.2~5/RELEASE_ARM64_T6000
  Available memory (MB): 16384
  Available CPU cores: 8

Activity

  1. added
    status: needs-triage
    validate-reproduction
    on Jan 13, 2025
  2. removed
    validate-reproduction
    on Jan 13, 2025
  3. added
    area: live-preview
    on Jan 14, 2025
  4. removed
    status: needs-triage
    on Jan 14, 2025
  5. added
    status: needs-triage
    status: verified
    on Jan 14, 2025
  6. removed
    status: verified
    status: needs-triage
    on Jan 14, 2025
  7. jeremyProwseYS commented on Jan 21, 2025

    @jeremyProwseYS

    +1 this is an issue I have recently run into - especially to do with hooks and autosave not reflecting changes in the admin UI. Only upon a hard refresh of the page does the updated value show.

  8. eustachi0 commented on Jan 24, 2025

    @eustachi0

    Same issue here. Thanks for reporting it

  9. jacobsfletch commented on Aug 11, 2025

    @jacobsfletch
    Member

    This was fixed for the Edit view in #10268 but persists in Live Preview mode.

    This was fixed in #12860. The live preview view is now mounted to the document root so the logic is no longer split between those views. Huge win in a lot of ways.

    Also, updates of the data in the hook is not received in the the admin.livePreview defined function for generating the preview url. Since the pathname to the page depends on the slug field, it's not possible to construct the correct pathname upon changing the slug.

    This is a known bug and something we definitely need to fix, see #13055. A similar problem is being looked at in #12956 but this only addresses the symptom, not the underlying issue.

    Also, i'm not sure if this is a bug or intended but when autosave:true is defined in the collection config, changes in hooks are not reflected at all, both in Edit and Live Preview mode.

    This is another known bug, see #10515. But I've got a fix for this queued up here: #13416.

  10. github-actions commented on Aug 19, 2025

    @github-actions
    Contributor

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

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

Metadata

Metadata

Assignees

Labels

area: live-preview

Type

No type

Projects

No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions