diff --git a/core/modules/comment/comment.module b/core/modules/comment/comment.module
index 166f6b7c57867ea13d65559b58833bdaf10f5b0e..8b28e76d33195b30a27d49e8de94f5af6ece167f 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 1535eb772efe2f8a0631e3dddf519976a12e4266..8b528d3cb398869e401b8ae5e9b9b92591f59267 100644
--- a/core/modules/user/user.module
+++ b/core/modules/user/user.module
@@ -116,16 +116,25 @@ function user_theme() {
 function user_page_build(&$page) {
   $path = drupal_get_path('module', 'user');
   $page['#attached']['css'][$path . '/css/user.module.css'] = array('every_page' => TRUE);
+}
+
+/**
+ * Implements hook_js_alter().
+ */
+function user_js_alter(&$javascript) {
+  // 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.
-  global $user;
-  $page['#attached']['js'][] = array(
-    'type' => 'setting',
-    'data' => array('user' => array(
-      'uid' => $user->id(),
-    )),
+  $javascript['settings']['data'][] = array(
+    'user' => array(
+      'uid' => \Drupal::currentUser()->id(),
+    ),
   );
 }