 core/includes/common.inc                           |    7 ++++
 core/modules/comment/comment.module                |   43 ++++++++++++++++++++
 .../lib/Drupal/comment/CommentViewBuilder.php      |   26 ++++++++----
 3 files changed, 69 insertions(+), 7 deletions(-)

diff --git a/core/includes/common.inc b/core/includes/common.inc
index 90641b6..b346369 100644
--- a/core/includes/common.inc
+++ b/core/includes/common.inc
@@ -3615,6 +3615,13 @@ function drupal_pre_render_links($element) {
       $element['#attached'] = drupal_merge_attached($element['#attached'], $child['#attached']);
     }
   }
+
+  // Collect all #post_render_cache callbacks associated with this element.
+  $post_render_cache = drupal_render_collect_post_render_cache($element);
+  if ($post_render_cache) {
+    $element['#post_render_cache'] = $post_render_cache;
+  }
+
   return $element;
 }
 
diff --git a/core/modules/comment/comment.module b/core/modules/comment/comment.module
index 9f8b282..1ea1357 100644
--- a/core/modules/comment/comment.module
+++ b/core/modules/comment/comment.module
@@ -1731,3 +1731,46 @@ function comment_library_info() {
   );
   return $libraries;
 }
+
+/**
+ * #post_render_cache callback; replaces the "edit" link placeholder.
+ *
+ * @param array $element
+ *   A render array with the following keys:
+ *   - #markup
+ *   - #attached
+ * @param array $context
+ *   An array with the following keys:
+ *   - token: a unique token to uniquely identify the placeholder list item
+ *   - entity_type: an entity type
+ *   - entity_id: an entity ID
+ *
+ * @return array $element
+ *   The updated $element.
+ */
+function comment_replace_edit_list_item(array $element, array $context) {
+  // Find the list item and the link placeholder using a regular expression.
+  $start = '<li class="comment-edit';
+  $token = $context['token'];
+  $regexp = '#' . preg_quote($start) . '.*' . preg_quote('">') . '(' . preg_quote($token) . ')' . preg_quote('</li>') . '#';
+  // Early-return if no match (which should be impossible).
+  if (!preg_match($regexp, $element['#markup'], $matches)) {
+    return $element;
+  }
+
+  // If the user has permission to update the entity, then replace the link
+  // placeholder with an actual link.
+  // @todo until https://drupal.org/node/1649780 lands, any time a list item
+  // gets removed, all list items after it will have the wrong "odd/even" class!
+  $entity = entity_load($context['entity_type'], $context['entity_id']);
+  if ($entity->access('update')) {
+    $link = l(t('edit'), "comment/{$entity->id()}/edit");
+    $element['#markup'] = str_replace($matches[1], $link, $element['#markup']);
+  }
+  // Otherwise, remove the list item completely.
+  else {
+    $element['#markup'] = str_replace($matches[0], '', $element['#markup']);
+  }
+
+  return $element;
+}
diff --git a/core/modules/comment/lib/Drupal/comment/CommentViewBuilder.php b/core/modules/comment/lib/Drupal/comment/CommentViewBuilder.php
index d79363b..71bc64b 100644
--- a/core/modules/comment/lib/Drupal/comment/CommentViewBuilder.php
+++ b/core/modules/comment/lib/Drupal/comment/CommentViewBuilder.php
@@ -7,6 +7,7 @@
 
 namespace Drupal\comment;
 
+use Drupal\Component\Utility\Crypt;
 use Drupal\Core\Access\CsrfTokenGenerator;
 use Drupal\Core\Entity\EntityControllerInterface;
 use Drupal\Core\Entity\EntityInterface;
@@ -169,13 +170,15 @@ protected function buildLinks(CommentInterface $entity, EntityInterface $comment
         );
       }
 
-      if ($entity->access('update')) {
-        $links['comment-edit'] = array(
-          'title' => t('edit'),
-          'href' => "comment/{$entity->id()}/edit",
-          'html' => TRUE,
-        );
-      }
+      // Placeholder for the "edit" link. Because $links may not contain render
+      // arrays, we cannot use a render_cache_placeholder: we must generate our
+      // own placeholder.
+      // @see comment_replace_edit_list_item()
+      $token = Crypt::randomStringHashed(55);
+      $links['comment-edit'] = array(
+        'title' => $token,
+      );
+
       if ($entity->access('create')) {
         $links['comment-reply'] = array(
           'title' => t('reply'),
@@ -217,6 +220,15 @@ protected function buildLinks(CommentInterface $entity, EntityInterface $comment
       // check.
       '#links' => $links,
       '#attributes' => array('class' => array('links', 'inline')),
+      '#post_render_cache' => array(
+        'comment_replace_edit_list_item' => array(
+          array(
+            'token' => $token,
+            'entity_type' => $entity->entityType(),
+            'entity_id' => $entity->id()
+          ),
+        ),
+      ),
     );
   }
 
