From 37cc6fbf27fa1417fddd9daaabd8b1a6ecd1db19 Mon Sep 17 00:00:00 2001 From: oidq Date: Fri, 2 Aug 2024 07:52:17 +0200 Subject: [PATCH] fix(web): prevent change-location suggestion race-condition (#11523) When debouncer activated on deletion, the handleSearchPlaces() function would fire a request with empty query. UI would then show Immich API error. --- .../shared-components/change-location.svelte | 11 +++++++---- 1 file changed, 7 insertions(+), 4 deletions(-) diff --git a/web/src/lib/components/shared-components/change-location.svelte b/web/src/lib/components/shared-components/change-location.svelte index 862ab913a2..f8d86929cb 100644 --- a/web/src/lib/components/shared-components/change-location.svelte +++ b/web/src/lib/components/shared-components/change-location.svelte @@ -69,15 +69,18 @@ }; const handleSearchPlaces = () => { - if (searchWord === '') { - return; - } - if (latestSearchTimeout) { clearTimeout(latestSearchTimeout); } showLoadingSpinner = true; + const searchTimeout = window.setTimeout(() => { + if (searchWord === '') { + places = []; + showLoadingSpinner = false; + return; + } + searchPlaces({ name: searchWord }) .then((searchResult) => { // skip result when a newer search is happening