 core/modules/comment/comment.module |    2 +-
 core/modules/user/user.module       |   19 +++++++++++++------
 2 files changed, 14 insertions(+), 7 deletions(-)

diff --git a/core/modules/comment/comment.module b/core/modules/comment/comment.module
index 2cd2d7a..20df738 100644
--- a/core/modules/comment/comment.module
+++ b/core/modules/comment/comment.module
@@ -595,7 +595,7 @@ function comment_entity_view(EntityInterface $entity, EntityDisplay $display, $v
       '#links' => $links,
       '#attributes' => array('class' => array('links', 'inline')),
     );
-    if ($view_mode == 'teaser' && \Drupal::moduleHandler()->moduleExists('history')) {
+    if ($view_mode == 'teaser' && \Drupal::moduleHandler()->moduleExists('history') && \Drupal::currentUser()->isAuthenticated()) {
       $entity->content['links']['#attached']['library'][] = array('comment', 'drupal.node-new-comments-link');
     }
   }
diff --git a/core/modules/user/user.module b/core/modules/user/user.module
index 16e93f4..b9db1cb 100644
--- a/core/modules/user/user.module
+++ b/core/modules/user/user.module
@@ -122,13 +122,20 @@ function user_page_build(&$page) {
  * Implements hook_js_alter().
  */
 function user_js_alter(&$javascript) {
-  if (!empty($javascript['settings'])) {
-    // Provide the user ID in drupalSettings to allow JavaScript code to customize
-    // the experience for the end user, rather than the server side, which would
-    // break the render cache.
-    global $user;
-    $javascript['settings']['user'] = array('uid' => $user->id());
+  // If >=1 JavaScript asset has declared a dependency on drupalSettings, the
+  // 'settings' key will exist. Thus when that key does not exist, return early.
+  if (!isset($javascript['settings'])) {
+    return;
   }
+
+  // Provide the user ID in drupalSettings to allow JavaScript code to customize
+  // the experience for the end user, rather than the server side, which would
+  // break the render cache.
+  $javascript['settings']['data'][] = array(
+    'user' => array(
+      'uid' => \Drupal::currentUser()->id(),
+    ),
+  );
 }
 
 /**
