payloadcms / payloadcms/payload
UnpublishButton does not reflect beforeChange hook modifications in form state
Nobody has claimed this yet.
- Dominant language
- TypeScript
- Stars
- 44.8k
- Forks
- 4.2k
- Avg merge
- 2d 21h
- Merged PRs (30d)
- 53
Description
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
publishedAtdate auto-set in sidebar - Open the document controls dropdown and click Unpublish, confirm
- Observe: Status changes to "Draft" but
publishedAtstill shows the old date - Verify via API:
fetch('/api/pages/<id>?depth=0').then(r => r.json()).then(d => console.log(d.publishedAt))returnsnull - Reload the page:
publishedAtfield 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
Contributor guide
First steps
- Read the whole issue, then the project's contributing guide.
- Comment on the issue to say you are picking it up — it saves two people doing the same work.
- Fork the repository and make your change on a branch.
- Open a pull request that references the issue number.
Research direction
Start in @payloadcms/ui/dist/elements/UnpublishButton/index.js around lines 112-116 and run the linked reproduction to observe the stale form value after unpublishing. Trace the successful response and form reset behavior, then verify that values changed by beforeChange are shown immediately without a reload.
Written by the indexing model from the issue text.
Assessment
- Tech stack
- react, typescript
- Domain
- frontend
- Issue type
- Bug
- Difficulty
- 3/5
- Estimated time
- 1-2 days
- Activity status
- Quiet
- Clarity
- Clearly specified
- Newbie friendliness
- 67/100