 core/lib/Drupal/Core/Cache/CacheableMetadata.php   | 6 +++---
 core/lib/Drupal/Core/Render/BubbleableMetadata.php | 4 ++--
 2 files changed, 5 insertions(+), 5 deletions(-)

diff --git a/core/lib/Drupal/Core/Cache/CacheableMetadata.php b/core/lib/Drupal/Core/Cache/CacheableMetadata.php
index 0a22f56..97cb14a 100644
--- a/core/lib/Drupal/Core/Cache/CacheableMetadata.php
+++ b/core/lib/Drupal/Core/Cache/CacheableMetadata.php
@@ -140,9 +140,9 @@ public function setCacheMaxAge($max_age) {
    */
   public function merge(CacheableMetadata $other) {
     $result = new static();
-    $result->contexts = Cache::mergeContexts($this->contexts, $other->contexts);
-    $result->tags = Cache::mergeTags($this->tags, $other->tags);
-    $result->maxAge = Cache::mergeMaxAges($this->maxAge, $other->maxAge);
+    $result->contexts = empty($this->contexts) ? $other->contexts : Cache::mergeContexts($this->contexts, $other->contexts);
+    $result->tags = empty($this->tags) ? $other->tags : Cache::mergeTags($this->tags, $other->tags);
+    $result->maxAge = $this->maxAge === Cache::PERMANENT ? $other->maxAge : Cache::mergeMaxAges($this->maxAge, $other->maxAge);
     return $result;
   }
 
diff --git a/core/lib/Drupal/Core/Render/BubbleableMetadata.php b/core/lib/Drupal/Core/Render/BubbleableMetadata.php
index 93a9310..34905dd 100644
--- a/core/lib/Drupal/Core/Render/BubbleableMetadata.php
+++ b/core/lib/Drupal/Core/Render/BubbleableMetadata.php
@@ -43,8 +43,8 @@ class BubbleableMetadata extends CacheableMetadata {
   public function merge(CacheableMetadata $other) {
     $result = parent::merge($other);
     if ($other instanceof BubbleableMetadata) {
-      $result->attached = \Drupal::service('renderer')->mergeAttachments($this->attached, $other->attached);
-      $result->postRenderCache = NestedArray::mergeDeep($this->postRenderCache, $other->postRenderCache);
+      $result->attached = empty($this->attached) ? $other->attached : \Drupal::service('renderer')->mergeAttachments($this->attached, $other->attached);
+      $result->postRenderCache = empty($this->postRenderCache) ? $other->postRenderCache : NestedArray::mergeDeep($this->postRenderCache, $other->postRenderCache);
     }
     return $result;
   }
