Skip to content

afterChange collection hook and drafts #4405

@cbratschi

Description

@cbratschi

Link to reproduction

private repo

Describe the Bug

The previousDoc value always returns either the last published version of the document or the last saved draft. This makes it difficult to react on field changes between published versions. For instance we want to add redirects whenever a slug changes but comparing previousDoc.slug to doc.slug will be wrong whenever a draft version was created in between.

The problem is there is no workaround available because in afterChange the last published version is already overwritten if the user publishes the changes.

A solution would be to add a originalDoc property which is equal to the last published version or last available draft if the document was not published before. This would make state handling much easier.

The documentation should be extended to include all necessary details.

To Reproduce

  1. create collection using draft
  2. add afterChange hook
  3. monitor previousDoc value

Payload Version

2.3.1

Adapters and Plugins

db-mongodb, bundler-webpack, live-preview

Metadata

Metadata

Assignees

Labels

status: needs-triagePossible bug which hasn't been reproduced yet

Type

No type

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions