From 202a0908114622f3b4e807aec1f5bec517c2c333 Mon Sep 17 00:00:00 2001 From: John O'Keefe Date: Mon, 19 Oct 2026 12:38:50 -0400 Subject: [PATCH] fix(ui): library restore no longer re-fires change on synced dropdowns MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit restoreLibrarySelection() ran on every page load via the header's x-init and always dispatched a synthetic `change` on #library-select after setting its value. On SSR pages the dropdown already renders the stored library (setSelectedLibrary keeps the cookie in sync and resolveLibrary renders from it), so the synthetic event re-ran the page's switch handler, whose fetches are hardcoded to page 1 / offset 0 — stomping freshly rendered content. Visible impact: the /series paginator snapped back to page 1 on every navigation whenever a specific library was stored (All Libraries short-circuits restore, which is why it only failed per-library). Silent impact: dashboard and collection-detail pages re-fetched their content on every single load. The restore now re-fires `change` only when the dropdown genuinely drifted from storage; the common synced case is a visual no-op. --- web/src/header.ts | 8 ++++++++ 1 file changed, 8 insertions(+) diff --git a/web/src/header.ts b/web/src/header.ts index 0aa5bc0d..44042141 100644 --- a/web/src/header.ts +++ b/web/src/header.ts @@ -32,6 +32,14 @@ const restoreLibrarySelection = (): void => { if (dropdown) { const option = dropdown.querySelector(`option[value="${savedLibrary}"]`); if (option) { + // SSR pages already render the select with the stored library + // (setSelectedLibrary keeps the cookie in sync and resolveLibrary + // renders from it). Re-firing `change` here made every page load + // re-run the page's switch handler — which re-fetches content at + // hardcoded page 1 / offset 0 and stomps URL-tracked state (this + // broke the /series paginator: page 2 snapped back to page 1). + // Only re-fire when the select actually drifted from storage. + if (dropdown.value === savedLibrary) return; dropdown.value = savedLibrary; dropdown.dispatchEvent(new Event("change", { bubbles: true })); console.log("Restored library selection:", savedLibrary);