fix(ui): library restore no longer re-fires change on synced dropdowns
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.
This commit is contained in:
1 parent
ee98c0fb3b
commit
202a090811
1 file changed
+8
@@ -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);
|
||||
|
||||
Reference in new issue
Block a user