From 63b07bfcbfd06dbc645cf603596072e7b14a6c8f Mon Sep 17 00:00:00 2001
From: Matthew Oliveira <m4olivei@gmail.com>
Date: Thu, 6 Mar 2025 16:31:25 -0500
Subject: [PATCH] Issue #3511374: Fix render array cacheability for navigation

---
 core/modules/navigation/src/NavigationRenderer.php | 9 +++++----
 1 file changed, 5 insertions(+), 4 deletions(-)

diff --git a/core/modules/navigation/src/NavigationRenderer.php b/core/modules/navigation/src/NavigationRenderer.php
index 8e29298092d6..60a7c15ee4f0 100644
--- a/core/modules/navigation/src/NavigationRenderer.php
+++ b/core/modules/navigation/src/NavigationRenderer.php
@@ -130,15 +130,16 @@ public function doBuildNavigation($build): array {
     if ($storage) {
       foreach ($storage->getSections() as $delta => $section) {
         $build[$delta] = $section->toRenderArray([]);
-        $build[$delta]['#cache']['contexts'] = ['user.permissions', 'theme', 'languages:language_interface'];
       }
     }
     // The render array is built based on decisions made by SectionStorage
     // plugins and therefore it needs to depend on the accumulated
     // cacheability of those decisions.
-    $cacheability->addCacheableDependency($logo_settings)
-      ->addCacheableDependency($this->configFactory->get('navigation.block_layout'));
-    $cacheability->applyTo($build);
+    CacheableMetadata::createFromRenderArray($build)
+      ->addCacheableDependency($cacheability)
+      ->addCacheableDependency($logo_settings)
+      ->addCacheableDependency($this->configFactory->get('navigation.block_layout'))
+      ->applyTo($build);
 
     $module_path = $this->requestStack->getCurrentRequest()->getBasePath() . '/' . $this->moduleExtensionList->getPath('navigation');
     $asset_url = $module_path . '/assets/fonts/inter-var.woff2';
-- 
GitLab