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

  1. Enable preview link for nodes.
  2. Create an unpublished node with a preview link.
  3. Clear drupal caches, then access the preview link.
  4. Edit the node and save a new revision with some new content.
  5. 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.

Command icon 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

richard.thomas created an issue. See original summary.

richard.thomas’s picture

Status: Active » Needs review

Added 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.

acbramley made their first commit to this issue’s fork.

acbramley’s picture

Version: 2.2.0-alpha2 » 2.x-dev
Status: Needs review » Fixed

Thanks!

Now that this issue is closed, review the contribution record.

As a contributor, attribute any organization that helped you, or if you volunteered your own time.

Maintainers, credit people who helped resolve this issue.

Status: Fixed » Closed (fixed)

Automatically closed - issue fixed for 2 weeks with no activity.