From a533ba946909ebf6fcb1bf6d0ac776e4cedd98f5 Mon Sep 17 00:00:00 2001 From: "david.jones" Date: Mon, 7 Sep 2026 16:51:07 +0100 Subject: [PATCH 1/5] update nav --- hugo/assets/scripts/components/async-loading.js | 15 +++++++++++++++ hugo/assets/scripts/datadog-docs.js | 2 +- hugo/layouts/partials/nav/left-nav.html | 7 +++++-- 3 files changed, 21 insertions(+), 3 deletions(-) diff --git a/hugo/assets/scripts/components/async-loading.js b/hugo/assets/scripts/components/async-loading.js index c43c864e648..9e0973d30d5 100644 --- a/hugo/assets/scripts/components/async-loading.js +++ b/hugo/assets/scripts/components/async-loading.js @@ -10,6 +10,7 @@ import {updateMainContentAnchors, reloadWistiaVidScripts, gtag, getCookieByName import configDocs from '../config/config-docs'; import { redirectCodeLang, addCodeTabEventListeners, addCodeBlockVisibilityToggleEventListeners, activateCodeLangNav, toggleMultiCodeLangNav } from './code-languages'; // eslint-disable-line import/no-cycle import { loadInstantSearch } from './instantsearch'; +import { getPathElement } from '../datadog-docs'; // eslint-disable-line import/no-cycle const { env } = document.documentElement.dataset; const { gaTag } = configDocs[env]; @@ -177,6 +178,20 @@ function loadPage(newUrl) { // update mainContent-wrapper classes mainContentWrapper.className = `${newmainContentWrapper.classList}`; + + // The left nav is server-rendered scoped to the current page's top-level section + // (see hugo/layouts/partials/nav/left-nav.html), so its content must be synced on + // every navigation -- otherwise navigating into a different section would leave the + // old section's nav items in place instead of the new section's. Swapping innerHTML + // (rather than replacing the container node) preserves the click listener bound to + // it in datadog-docs.js. + const currentLeftNav = document.querySelector('.sidenav-nav-js-load'); + const newLeftNav = newDocument.querySelector('.sidenav-nav-js-load'); + + if (currentLeftNav && newLeftNav) { + currentLeftNav.innerHTML = newLeftNav.innerHTML; + getPathElement(); + } } else { window.location.href = newUrl; } diff --git a/hugo/assets/scripts/datadog-docs.js b/hugo/assets/scripts/datadog-docs.js index 540839da76f..6abfec6446b 100644 --- a/hugo/assets/scripts/datadog-docs.js +++ b/hugo/assets/scripts/datadog-docs.js @@ -178,7 +178,7 @@ function hasParentLi(el) { } } -function getPathElement(event = null) { +export function getPathElement(event = null) { let path = window.location.pathname; const activeMenus = document.querySelectorAll( '.side .sidenav-nav-js-load .active, header .sidenav-nav-js-load .active' diff --git a/hugo/layouts/partials/nav/left-nav.html b/hugo/layouts/partials/nav/left-nav.html index d03fe06ecae..33935040efb 100644 --- a/hugo/layouts/partials/nav/left-nav.html +++ b/hugo/layouts/partials/nav/left-nav.html @@ -29,8 +29,11 @@