From 5614ed6396195184b7adb60673d6287beb8972cc Mon Sep 17 00:00:00 2001 From: Brian Munkholm Date: Thu, 12 Feb 2026 16:14:02 +0100 Subject: [PATCH 1/2] Fix TOC expansion for direct links --- src/crate/theme/rtd/crate/static/js/custom.js | 22 +++++++++++++++---- 1 file changed, 18 insertions(+), 4 deletions(-) diff --git a/src/crate/theme/rtd/crate/static/js/custom.js b/src/crate/theme/rtd/crate/static/js/custom.js index b69c4095..1458daf1 100644 --- a/src/crate/theme/rtd/crate/static/js/custom.js +++ b/src/crate/theme/rtd/crate/static/js/custom.js @@ -79,6 +79,21 @@ document.addEventListener('DOMContentLoaded', () => { // Restore state on page load restoreNavState(); + let stateChanged = false; + + // Ensure the path to the current page is always expanded in the TOC. + // When opening a page directly via URL (not by navigating within the + // site), restoreNavState() may set checkboxes to a previously saved + // state that doesn't include the current page's ancestors as expanded. + // Furo marks these ancestors with the "current" class, so we force + // their checkboxes open. + document.querySelectorAll('.sidebar-tree li.current > .toctree-checkbox').forEach((checkbox) => { + if (!checkbox.checked) { + checkbox.checked = true; + stateChanged = true; + } + }); + // Auto-expand sections marked with data-auto-expand="true" // Used for Database Drivers when viewing a driver project. // Only auto-expand if user hasn't explicitly set a preference for this checkbox. @@ -91,7 +106,6 @@ document.addEventListener('DOMContentLoaded', () => { // Ignore parse errors, treat as no preferences } } - let autoExpandStateChanged = false; document.querySelectorAll('[data-auto-expand="true"]').forEach((li) => { const checkbox = li.querySelector('.toctree-checkbox'); @@ -99,13 +113,13 @@ document.addEventListener('DOMContentLoaded', () => { // Only auto-expand if user has no saved preference for this checkbox if (!(checkbox.id in userPreferences)) { checkbox.checked = true; - autoExpandStateChanged = true; + stateChanged = true; } } }); - // Save the auto-expanded state so it persists - if (autoExpandStateChanged) { + // Save state if initialization expanded any sections + if (stateChanged) { saveNavState(); } From f0c1766e537a24d443e2d6af26441e4c2835131f Mon Sep 17 00:00:00 2001 From: Brian Munkholm Date: Thu, 12 Feb 2026 16:17:55 +0100 Subject: [PATCH 2/2] change log --- CHANGES.rst | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/CHANGES.rst b/CHANGES.rst index 9e9c5d97..86541694 100644 --- a/CHANGES.rst +++ b/CHANGES.rst @@ -5,6 +5,11 @@ CHANGES Unreleased ---------- + +- Fixed TOC expansion for direct links. + +2026/02/12 0.49.0 +----------------- - Restructure top-level TOC by unfolding Handbook into groups with captions. 2026/01/27 0.48.0