From 6080e6e827250b069039538cb5d08ee7492b71c1 Mon Sep 17 00:00:00 2001 From: Alex Date: Sat, 21 Dec 2024 13:26:01 -0600 Subject: [PATCH] fix(web): infinite loop browser navigation crash admin settings page (#14850) * fix(web): infinite loop browser navigation crash admin settings page * pr feedback --- .../settings/setting-accordion-state.svelte | 19 +++++++++---------- 1 file changed, 9 insertions(+), 10 deletions(-) diff --git a/web/src/lib/components/shared-components/settings/setting-accordion-state.svelte b/web/src/lib/components/shared-components/settings/setting-accordion-state.svelte index 4d97ee5cc6..6b3ae81685 100644 --- a/web/src/lib/components/shared-components/settings/setting-accordion-state.svelte +++ b/web/src/lib/components/shared-components/settings/setting-accordion-state.svelte @@ -9,9 +9,9 @@ import { writable, type Writable } from 'svelte/store'; import { createContext } from '$lib/utils/context'; import { page } from '$app/state'; - import { handlePromiseError } from '$lib/utils'; import { goto } from '$app/navigation'; import type { Snippet } from 'svelte'; + import { handlePromiseError } from '$lib/utils'; const getParamValues = (param: string) => { return new Set((page.url.searchParams.get(param) || '').split(' ').filter((x) => x !== '')); @@ -26,17 +26,16 @@ let { queryParam, state = writable(getParamValues(queryParam)), children }: Props = $props(); setAccordionState(state); - $effect(() => { - if (queryParam && $state) { - const searchParams = new URLSearchParams(page.url.searchParams); - if ($state.size > 0) { - searchParams.set(queryParam, [...$state].join(' ')); - } else { - searchParams.delete(queryParam); - } + const searchParams = new URLSearchParams(page.url.searchParams); - handlePromiseError(goto(`?${searchParams.toString()}`, { replaceState: true, noScroll: true, keepFocus: true })); + $effect(() => { + if ($state.size > 0) { + searchParams.set(queryParam, [...$state].join(' ')); + } else { + searchParams.delete(queryParam); } + + handlePromiseError(goto(`?${searchParams.toString()}`, { replaceState: true, noScroll: true, keepFocus: true })); });