From 087ff36d5d568134c392e81d8ff0f7e0d598bb1f Mon Sep 17 00:00:00 2001 From: Shane O'Donnell Date: Fri, 13 Jun 2025 07:22:25 -0400 Subject: [PATCH] Fix stale search (#189) Fixes an issue where, after chord list is updated (e.g. by a deletion), the search results continue to use the old list and indices, resulting in incorrect search results. --- src/routes/(app)/config/chords/+page.svelte | 10 ++++++++++ 1 file changed, 10 insertions(+) diff --git a/src/routes/(app)/config/chords/+page.svelte b/src/routes/(app)/config/chords/+page.svelte index 5a50620d..0143a90b 100644 --- a/src/routes/(app)/config/chords/+page.svelte +++ b/src/routes/(app)/config/chords/+page.svelte @@ -183,9 +183,11 @@ } const searchFilter = writable(undefined); + let currentSearchQuery = $state(""); async function search(index: FlexSearch.Index, event: Event) { const query = (event.target as HTMLInputElement).value; + currentSearchQuery = query; searchFilter.set( query && searchIndex ? ((await index.searchAsync(query)) as number[]) @@ -194,6 +196,13 @@ page = 0; } + // Re-run search when chords change to fix stale indices + $effect(() => { + if (currentSearchQuery && $searchIndex) { + search($searchIndex, { target: { value: currentSearchQuery } } as any); + } + }); + function insertChord(actions: number[]) { const id = JSON.stringify(actions); if ($chords.some((it) => JSON.stringify(it.actions) === id)) { @@ -273,6 +282,7 @@ $searchIndex && search($searchIndex, event)} class:loading={progress !== $chords.length} />