diff --git a/core/modules/node/src/ContextProvider/NodeRouteContext.php b/core/modules/node/src/ContextProvider/NodeRouteContext.php
index 2e10a8a643..767f445828 100644
--- a/core/modules/node/src/ContextProvider/NodeRouteContext.php
+++ b/core/modules/node/src/ContextProvider/NodeRouteContext.php
@@ -51,12 +51,14 @@ public function getRuntimeContexts(array $unqualified_context_ids) {
       $value = Node::create(['type' => $node_type->id()]);
     }
 
-    $cacheability = new CacheableMetadata();
-    $cacheability->setCacheContexts(['route']);
+    if ($value) {
+      $cacheability = new CacheableMetadata();
+      $cacheability->setCacheContexts(['route']);
 
-    $context = new Context($context_definition, $value);
-    $context->addCacheableDependency($cacheability);
-    $result['node'] = $context;
+      $context = new Context($context_definition, $value);
+      $context->addCacheableDependency($cacheability);
+      $result['node'] = $context;
+    }
 
     return $result;
   }
