diff --git a/flag/flag.module b/flag/flag.module
index 75fd868..a2c1ee4 100644
--- a/flag/flag.module
+++ b/flag/flag.module
@@ -323,8 +323,10 @@ function flag_entity_view(array &$build, EntityInterface $entity, EntityViewDisp
   $flags = $flag_service->getFlags($entity->getEntityTypeID(), $entity->bundle());
 
   foreach ($flags as $flag) {
-    $build['#cache']['tags'] = Cache::mergeTags($build['#cache']['tags'], $flag->getCacheTags());
-
+    if (!empty($build['#cache']['tags'])) {
+      $build['#cache']['tags'] = Cache::mergeTags($build['#cache']['tags'], $flag->getCacheTags());
+    }
+    
     // Do not display the flag if disabled.
     if (!$flag->isEnabled()){
       continue;
