Problem/Motivation
The \Drupal\preview_link\Controller\PreviewLinkController::preview() controller method adds a "session" cache context to the entity view render array. However it creates a new empty CacheableMetadata object then applies that to the array, this removes any existing tags/contexts.
This means in some circumstances if that render result is the one that gets cached, it doesn't have the correct tags to be invalidated when the node is updated and the preview link continues to render the old revision.
Steps to reproduce
- Enable preview link for nodes.
- Create an unpublished node with a preview link.
- Clear drupal caches, then access the preview link.
- Edit the node and save a new revision with some new content.
- Access the preview link again, it won't reflect the changes to the node.
Proposed resolution
Use CacheableMetadata::createFromRenderArray() instead to preserve the existing cacheability metadata when adding the session.
Issue fork preview_link-3555104
Show commands
Start within a Git clone of the project using the version control instructions.
Or, if you do not have SSH keys set up on git.drupalcode.org:
Comments
Comment #3
richard.thomas commentedAdded an MR with the fix, I've done some manual testing here and verified it fixes the issue with the steps mentioned in the issue description.
Comment #6
acbramley commentedThanks!