From 9beb5d68b55ebe1c50a7b8aebc005d74f34a9f36 Mon Sep 17 00:00:00 2001 From: Vinta Chen Date: Tue, 27 Oct 2026 21:04:16 +0800 Subject: [PATCH] fix: open linked entry row when the hash changes after load An entry link like /categories/caching/#entry-diskcache did not open its row when only the hash changed on an already-loaded page (editing the URL, back/forward), because the row-opening logic ran only on initial load. Co-Authored-By: Claude --- website/static/main.js | 13 +++++++++---- 1 file changed, 9 insertions(+), 4 deletions(-) diff --git a/website/static/main.js b/website/static/main.js index 79151054..7aece8cd 100644 --- a/website/static/main.js +++ b/website/static/main.js @@ -332,6 +332,14 @@ function openEntryRow(row) { setRowOpen(row, true); } +function openHashedRow() { + const linkedRow = document.getElementById(decodeURIComponent(location.hash.slice(1))); + if (linkedRow && linkedRow.matches("tr.row")) openEntryRow(linkedRow); +} + +// Editing the hash or going back/forward on the same page does not reload it +window.addEventListener("hashchange", openHashedRow); + // Group headings are hidden while sorted flat or filtered out by search, so a link to one must restore them first document.addEventListener("click", function (e) { const link = e.target.closest('a[href*="#"]'); @@ -447,8 +455,5 @@ if (backToTop) { } updateSortIndicators(); // Filtering collapses rows, so open a linked entry after restoring URL state. - if (location.hash) { - const linkedRow = document.getElementById(decodeURIComponent(location.hash.slice(1))); - if (linkedRow && linkedRow.matches("tr.row")) openEntryRow(linkedRow); - } + if (location.hash) openHashedRow(); })();