From b68ca985d3201da7f88135ccd426ac310cba7f2e Mon Sep 17 00:00:00 2001 From: Denozordec Date: Fri, 10 Apr 2026 16:17:54 +0700 Subject: [PATCH] Refactor alias filter handling in Svelte components to prevent unnecessary updates - Added a check to prevent alias filter changes from triggering updates if the selected alias remains the same. - Introduced a reactive effect to apply alias changes only when the component is rendered in the browser, improving performance and clarity in data handling. --- web/src/routes/+page.svelte | 7 +++++++ web/src/routes/users/+page.svelte | 7 +++++++ 2 files changed, 14 insertions(+) diff --git a/web/src/routes/+page.svelte b/web/src/routes/+page.svelte index 4357434..004869f 100644 --- a/web/src/routes/+page.svelte +++ b/web/src/routes/+page.svelte @@ -236,6 +236,7 @@ } async function handleAliasFilterChange(nextAlias: string) { + if (nextAlias === aliasFilter) return; aliasFilter = nextAlias; await applyAliasIfChanged(nextAlias); } @@ -251,6 +252,12 @@ async function handleAliasFilterChange(nextAlias: string) { void load(); }); + $effect(() => { + if (typeof window === 'undefined') return; + const nextAlias = aliasFilter; + void applyAliasIfChanged(nextAlias); + }); + let staleSeconds = $derived.by(() => lastSuccessAtMs == null ? null : Math.max(0, Math.floor((nowMs - lastSuccessAtMs) / 1000)) ); diff --git a/web/src/routes/users/+page.svelte b/web/src/routes/users/+page.svelte index fbf74ad..507b82c 100644 --- a/web/src/routes/users/+page.svelte +++ b/web/src/routes/users/+page.svelte @@ -135,6 +135,7 @@ } async function handleAliasFilterChange(nextAlias: string) { + if (nextAlias === aliasFilter) return; aliasFilter = nextAlias; await applyAliasIfChanged(nextAlias); } @@ -151,6 +152,12 @@ void load(); }); + $effect(() => { + if (typeof window === 'undefined') return; + const nextAlias = aliasFilter; + void applyAliasIfChanged(nextAlias); + }); + let staleSeconds = $derived.by(() => lastSuccessAtMs == null ? null : Math.max(0, Math.floor((nowMs - lastSuccessAtMs) / 1000)) );