diff --git a/src/lib/apis/notes/index.ts b/src/lib/apis/notes/index.ts index d8b00d7184..3e923ee526 100644 --- a/src/lib/apis/notes/index.ts +++ b/src/lib/apis/notes/index.ts @@ -131,7 +131,8 @@ export const searchNotes = async ( permission: string | null = null, sortKey: string | null = null, page: number | null = null, - direction: string | null = null + direction: string | null = null, + signal?: AbortSignal ) => { let error = null; const searchParams = new URLSearchParams(); @@ -162,6 +163,7 @@ export const searchNotes = async ( const res = await fetch(`${WEBUI_API_BASE_URL}/notes/search?${searchParams.toString()}`, { method: 'GET', + signal, headers: { Accept: 'application/json', 'Content-Type': 'application/json', @@ -176,6 +178,7 @@ export const searchNotes = async ( return json; }) .catch((err) => { + if (signal?.aborted) return null; error = err.detail; console.error(err); return null; diff --git a/src/lib/components/notes/Notes.svelte b/src/lib/components/notes/Notes.svelte index 248ddf8291..1361c4d23f 100644 --- a/src/lib/components/notes/Notes.svelte +++ b/src/lib/components/notes/Notes.svelte @@ -74,6 +74,7 @@ let query = ''; let searchDebounceTimer: ReturnType; + let searchController: AbortController; let sortKey = 'updated_at'; let sortDirection = 'desc'; @@ -200,6 +201,10 @@ : `/notes/${note.id}`; const getItemsPage = async () => { + searchController?.abort(); + searchController = new AbortController(); + const { signal } = searchController; + itemsLoading = true; if (viewOption === 'created') { @@ -213,11 +218,14 @@ permission, sortKey, page, - sortKey ? sortDirection : null + sortKey ? sortDirection : null, + signal ).catch(() => { return []; }); + if (signal.aborted) return; + if (res) { total = res.total; const pageItems = res.items; @@ -349,6 +357,7 @@ window.addEventListener('blur', onBlur); return () => { + searchController?.abort(); clearTimeout(searchDebounceTimer); window.removeEventListener('focusin', onFocusIn);