diff --git a/core/modules/taxonomy/taxonomy.module b/core/modules/taxonomy/taxonomy.module
index e82edfc..bfc54d2 100644
--- a/core/modules/taxonomy/taxonomy.module
+++ b/core/modules/taxonomy/taxonomy.module
@@ -1308,8 +1308,12 @@ function taxonomy_field_formatter_prepare_view($entity_type, $entities, $field,
   // Collect every possible term attached to any of the fieldable entities.
   foreach ($entities as $id => $entity) {
     foreach ($items[$id] as $delta => $item) {
+      // Remove NULL tids.
+      if (empty($item['tid'])) {
+        unset($items[$id][$delta]);
+      }
       // Force the array key to prevent duplicates.
-      if ($item['tid'] != 'autocreate') {
+      elseif ($item['tid'] != 'autocreate') {
         $tids[$item['tid']] = $item['tid'];
       }
     }
