Change record status: 
Project: 
Introduced in branch: 
8.x
Description: 

Most node and comment op links depend on a user's role, but some depend on a specific user: the "edit own comments" permission is the best example in Drupal core. But contrib might do crazy things: additional node or comment op links that depend on node/entity access modules, or even time-based links.

Of course, if user A may edit comment X because that's his own comment, then we cannot render cache that comment. And since comments are rendered as part of nodes (or whatever other type the commented on entity may be), they also break node render caching. That's of course less than ideal.

Thanks to the addition of #lazy_builders and placeholders to Drupal 8's Render API, we can now choose to render nodes and comments without the links and with a placeholder instead, and then using a #lazy_builder callback render the node and comment links for the current user.
So that's precisely what we did: we only render a placeholder where the node/comment links will end up, the placeholder gets stored in the render cache, and a #lazy_builder callback then replaces the placeholder with the links for the current user. Result: node nor comment links no longer break the render cache.

The consequence is that you must now use the newly added hook_node_links_alter() and hook_comment_links_alter() hooks to alter/extend node and comment links, rather than using hook_entity_view_alter().

Impacts: 
Module developers