diff --git a/core/modules/comment/src/CommentViewBuilder.php b/core/modules/comment/src/CommentViewBuilder.php
index 51a9185853..bac67f1b48 100644
--- a/core/modules/comment/src/CommentViewBuilder.php
+++ b/core/modules/comment/src/CommentViewBuilder.php
@@ -98,6 +98,7 @@ public function buildComponents(array &$build, array $entities, array $displays,
 
     // A counter to track the indentation level.
     $current_indent = 0;
+    $attach_history = $this->moduleHandler->moduleExists('history') && $this->currentUser->isAuthenticated();
 
     foreach ($entities as $id => $entity) {
       if ($build[$id]['#comment_threaded']) {
@@ -143,7 +144,7 @@ public function buildComponents(array &$build, array $entities, array $displays,
         $build[$id]['#attached'] = [];
       }
       $build[$id]['#attached']['library'][] = 'comment/drupal.comment-by-viewer';
-      if ($this->moduleHandler->moduleExists('history') && $this->currentUser->isAuthenticated()) {
+      if ($attach_history && $commented_entity->getEntityTypeId() === 'node') {
         $build[$id]['#attached']['library'][] = 'comment/drupal.comment-new-indicator';
 
         // Embed the metadata for the comment "new" indicators on this node.
diff --git a/core/modules/comment/tests/src/Functional/CommentEntityTest.php b/core/modules/comment/tests/src/Functional/CommentEntityTest.php
new file mode 100644
index 0000000000..c1fe78074e
--- /dev/null
+++ b/core/modules/comment/tests/src/Functional/CommentEntityTest.php
@@ -0,0 +1,84 @@
+<?php
+/**
+ * @file
+ * Contains Drupal\Tests\comment\Functional\CommentEntityTest.
+ */
+
+namespace Drupal\Tests\comment\Functional;
+
+use Drupal\comment\Entity\CommentType;
+use Drupal\comment\Plugin\Field\FieldType\CommentItemInterface;
+use Drupal\Core\Language\LanguageInterface;
+use Drupal\comment\CommentInterface;
+use Drupal\Tests\taxonomy\Functional\TaxonomyTestTrait;
+use Drupal\user\RoleInterface;
+use Drupal\comment\Entity\Comment;
+
+/**
+ * Tests comments with other entities.
+ *
+ * @group comment
+ */
+class CommentEntityTest extends CommentTestBase {
+
+  /**
+   * Modules to install.
+   *
+   * @var array
+   */
+  public static $modules = ['block', 'comment', 'node', 'history', 'field_ui', 'datetime', 'taxonomy'];
+
+  use TaxonomyTestTrait;
+
+  protected $vocab;
+  protected $commentType;
+
+  protected function setUp() {
+    parent::setUp();
+
+    $this->vocab = $this->createVocabulary();
+    $this->commentType = CommentType::create([
+      'id' => 'taxonomy_comment',
+      'label' => 'Taxonomy comment',
+      'description' => '',
+      'target_entity_type_id' => 'taxonomy_term',
+    ]);
+    $this->commentType->save();
+    $this->addDefaultCommentField(
+      'taxonomy_term',
+      $this->vocab->id(),
+      'field_comment',
+      CommentItemInterface::OPEN,
+      $this->commentType->id()
+    );
+  }
+
+  /**
+   * Tests CSS classes on comments.
+   */
+  public function testEntityChanges() {
+    $this->drupalLogin($this->webUser);
+    // Create a new node.
+    $term = $this->createTerm($this->vocab, ['uid' => $this->webUser->id()]);
+
+    // Add a comment.
+    /** @var \Drupal\comment\CommentInterface $comment */
+    $comment = Comment::create([
+      'entity_id' => $term->id(),
+      'entity_type' => 'taxonomy_term',
+      'field_name' => 'field_comment',
+      'uid' => $this->webUser->id(),
+      'status' => CommentInterface::PUBLISHED,
+      'subject' => $this->randomMachineName(),
+      'language' => LanguageInterface::LANGCODE_NOT_SPECIFIED,
+      'comment_body' => [LanguageInterface::LANGCODE_NOT_SPECIFIED => [$this->randomMachineName()]],
+    ]);
+    $comment->save();
+
+    // Request the node with the comment.
+    $this->drupalGet('taxonomy/term/' . $term->id());
+    $settings = $this->getDrupalSettings();
+    $this->assertFalse(isset($settings['ajaxPageState']['libraries']) && in_array('comment/drupal.comment-new-indicator', explode(',', $settings['ajaxPageState']['libraries'])), 'drupal.comment-new-indicator library is present.');
+    $this->assertFalse(isset($settings['history']['lastReadTimestamps']) && in_array($term->id(), array_keys($settings['history']['lastReadTimestamps'])), 'history.lastReadTimestamps is present.');
+  }
+}
\ No newline at end of file
