From bfbfe81c0804114b54aa0e81351b6cb667b144a5 Mon Sep 17 00:00:00 2001 From: lilydjwg Date: Fri, 22 Jul 2022 13:39:09 +0800 Subject: [PATCH] avoid old requests to mess up results --- src/App.svelte | 8 +++++++- 1 file changed, 7 insertions(+), 1 deletion(-) diff --git a/src/App.svelte b/src/App.svelte index 6e2f4fa..ead3ab0 100644 --- a/src/App.svelte +++ b/src/App.svelte @@ -17,6 +17,7 @@ let sender: string; let selected_init: string; let our_hash_change = false; + let abort = new AbortController(); setContext("LUOXU_URL", LUOXU_URL); @@ -91,6 +92,8 @@ } async function do_search(more?: any) { + abort.abort(); + abort = new AbortController(); if (!group && !islocal) { error = "请选择要搜索的群组"; return; @@ -130,9 +133,12 @@ now = new Date(); loading = true; try { - const res = await fetch(url); + const res = await fetch(url, {signal: abort.signal}); const r = await res.json(); loading = false; + if (abort.signal.aborted) { + return []; + } if (more) { return r; } else {