"Unpublish" effectively does nothing
Describe the Bug.
The admin panel's "unpublish" feature does not work as expected, as described in the reprod steps.
Recommended solution: replace "unpublish" with "Revert to...." which allows you to select any previous published version to revert to, or "Unpublish" the entire doc.
Related issue: https://github.com/payloadcms/payload/issues/11942
Reproduction Steps
- On a collection with autosave and draft enabled, create a new document and publish.
- You should have v1 - initial doc, v2 - autosave, v3 - current published version.
- Make some changes - v4 is created with status "autosave, draft".
- Publish v4, creating v5 with status "published".
- Click "unpublish" on the newly created v5.
- The document leaves v5 as "published" and creates a v6 with status "draft"....
So, your newly added changes are left intact, (not "unpublished"), and there is no way to fully "unpublish" a document/post unless you delete it or manually set status: draft on each version of the document.
Environment Info
Binaries:
Node: 22.12.0
npm: 10.9.0
Yarn: N/A
pnpm: 9.15.0
Relevant Packages:
payload: 3.35.1
next: 15.3.0
@payloadcms/db-mongodb: 3.35.1
@payloadcms/email-nodemailer: 3.35.1
@payloadcms/graphql: 3.35.1
@payloadcms/live-preview: 3.35.1
@payloadcms/live-preview-react: 3.35.1
@payloadcms/next/utilities: 3.35.1
@payloadcms/payload-cloud: 3.35.1
@payloadcms/plugin-cloud-storage: 3.35.1
@payloadcms/plugin-form-builder: 3.35.1
@payloadcms/plugin-nested-docs: 3.35.1
@payloadcms/plugin-redirects: 3.35.1
@payloadcms/plugin-search: 3.35.1
@payloadcms/plugin-seo: 3.35.1
@payloadcms/richtext-lexical: 3.35.1
@payloadcms/storage-uploadthing: 3.35.1
@payloadcms/translations: 3.35.1
@payloadcms/ui/shared: 3.35.1
react: 19.1.0
react-dom: 19.1.0
A workaround I've found is to just add a "published" checkbox field, and make sure to respect that anywhere we query for the collection. Still unsure how to remove un-published posts from the auto generated search results though.
I took note of this on this morning as well; "Unpublish" seems to do virtually nothing, and there seems to be no way to hook into the action either.
I had some code that would revalidate a lot of cached paths when a document was unpublished (in order to hide it), when I noticed that the revalidation was actually invoked every time autosave triggered while editing a published document.
I noticed the issue @nilskaspersson mentioned above, and I also have a (typical) use case right now where I need to hook into the unpublish button, and there seems to be no way to handle this.
Had a similar challenge on our project. Our workaround leverages the work from @cbratschi in #4616. We can filter out saves (manual or autosave) by checking for draft: true in the req's query params. The unpublish event occurs without those params with doc._status === 'draft (at least for now).
Unfortunately, there is no way to tell the difference between a doc being published via the "Publish" button and a doc's draft being discarded with the "Revert to Published" button.
It would help us greatly to have specific events or query params for publish, unpublish, revert to published, etc.
The introduction of soft delete (trash) added some more complexity and there is no hook for soft delete/undelete either. I hope this gets at least addressed in Payload 4.x together with better localized documents handling.