Describe the Bug
When a beforeChange hook modifies field values during an unpublish operation (e.g., setting publishedAt to null when transitioning from published to draft), the database is updated correctly but the admin UI form still shows the old value. A manual page reload shows the correct value.
Root cause: In @payloadcms/ui/dist/elements/UnpublishButton/index.js (lines 112-116), after a successful unpublish, the form is reset with dataFromProps (stale data from initial page load) and only _status is overridden:
if (res.status === 200) {
void resetForm({
...(dataFromProps || {}),
_status: 'draft'
});
The server response is never read (res.json() is not called on success), so any beforeChange hook modifications are invisible to the user until they reload. The fix in PR #13416 (v3.51.0) addressed this for autosave but the Unpublish button has its own form reset logic that still uses stale data.
Link to the code that reproduces this issue
https://github.com/busbyk/unpublish-hook-stale-form-reproduction
Reproduction Steps
- Clone the repo and run
pnpm install && pnpm dev
- Log in to admin panel at
http://localhost:3000/admin
- Create a new Page with a title and click Publish -- note the
publishedAt date auto-set in sidebar
- Open the document controls dropdown and click Unpublish, confirm
- Observe: Status changes to "Draft" but
publishedAt still shows the old date
- Verify via API:
fetch('/api/pages/<id>?depth=0').then(r => r.json()).then(d => console.log(d.publishedAt)) returns null
- Reload the page:
publishedAt field is now correctly empty
Which area(s) are affected?
area: ui
Environment Info
Binaries:
Node: 24.13.0
npm: 11.6.2
pnpm: 10.28.0
Relevant Packages:
payload: 3.85.0
next: 16.2.6
@payloadcms/db-sqlite: 3.85.0
@payloadcms/ui/shared: 3.85.0
@payloadcms/richtext-lexical: 3.85.0
react: 19.2.6
react-dom: 19.2.6
Operating System:
Platform: darwin
Arch: arm64
Describe the Bug
When a
beforeChangehook modifies field values during an unpublish operation (e.g., settingpublishedAttonullwhen transitioning from published to draft), the database is updated correctly but the admin UI form still shows the old value. A manual page reload shows the correct value.Root cause: In
@payloadcms/ui/dist/elements/UnpublishButton/index.js(lines 112-116), after a successful unpublish, the form is reset withdataFromProps(stale data from initial page load) and only_statusis overridden:The server response is never read (
res.json()is not called on success), so anybeforeChangehook modifications are invisible to the user until they reload. The fix in PR #13416 (v3.51.0) addressed this for autosave but the Unpublish button has its own form reset logic that still uses stale data.Link to the code that reproduces this issue
https://github.com/busbyk/unpublish-hook-stale-form-reproduction
Reproduction Steps
pnpm install && pnpm devhttp://localhost:3000/adminpublishedAtdate auto-set in sidebarpublishedAtstill shows the old datefetch('/api/pages/<id>?depth=0').then(r => r.json()).then(d => console.log(d.publishedAt))returnsnullpublishedAtfield is now correctly emptyWhich area(s) are affected?
area: ui
Environment Info