From 1cf061b792f18f34c5fc2bb479805e672638ecd0 Mon Sep 17 00:00:00 2001 From: "google-labs-jules[bot]" <161369871+google-labs-jules[bot]@users.noreply.github.com> Date: Tue, 10 Feb 2026 21:27:23 +0000 Subject: [PATCH] =?UTF-8?q?=E2=9A=A1=20Bolt:=20Optimize=20domain=20search?= =?UTF-8?q?=20with=20input=20event=20and=20race=20condition=20handling?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit - Replace `on:keyup` with `on:input` to avoid redundant searches on non-character keys. - Add duplicate search check to prevent unnecessary API calls. - Implement race condition handling to discard stale responses. - Fix `debounceTimer` type for browser compatibility. - Wrap API call in try/catch to ensure loading state reset. Co-authored-by: Yeboster <23556525+Yeboster@users.noreply.github.com> --- src/routes/DomainSearch.svelte | 20 +++++++++++++++----- 1 file changed, 15 insertions(+), 5 deletions(-) diff --git a/src/routes/DomainSearch.svelte b/src/routes/DomainSearch.svelte index 2cde1b3..7f06341 100644 --- a/src/routes/DomainSearch.svelte +++ b/src/routes/DomainSearch.svelte @@ -15,7 +15,7 @@ let domainName: string = ''; let nameSearched: string = ''; let isLoading: boolean = false; - let debounceTimer: NodeJS.Timeout; + let debounceTimer: ReturnType; $: errors = invalid ? validator.getErrors() : []; $: invalid = domainName !== '' && !validator.validate(domainName, { raiseError: false }); @@ -36,12 +36,22 @@ return goto(url); } - nameSearched = domainName.toLocaleLowerCase(); + const currentName = domainName.toLocaleLowerCase(); + if (!submit && currentName === nameSearched) return; + + nameSearched = currentName; isLoading = true; - domain = await $metaNamesSdk.domainRepository.find(domainName); + try { + const result = await $metaNamesSdk.domainRepository.find(domainName); + if (currentName !== nameSearched) return; - isLoading = false; + domain = result; + isLoading = false; + } catch (error) { + console.error(error); + if (currentName === nameSearched) isLoading = false; + } } async function submit() { @@ -55,7 +65,7 @@ class="domain-input" variant="outlined" bind:value={domainName} - on:keyup={() => debounce()} + on:input={() => debounce()} bind:invalid label="Domain name" withTrailingIcon