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
- create collection using draft
- add afterChange hook
- monitor previousDoc value
Payload Version
2.3.1
Adapters and Plugins
db-mongodb, bundler-webpack, live-preview
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
Payload Version
2.3.1
Adapters and Plugins
db-mongodb, bundler-webpack, live-preview