From c2cfe446fdb1c9c785b7bf4d9cf0a4a7f522730a Mon Sep 17 00:00:00 2001 From: "google-labs-jules[bot]" <161369871+google-labs-jules[bot]@users.noreply.github.com> Date: Mon, 9 Feb 2026 20:42:28 +0000 Subject: [PATCH] =?UTF-8?q?=E2=9A=A1=20Bolt:=20Fix=20race=20condition=20in?= =?UTF-8?q?=20domain=20search?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit - Introduced request ID tracking to discard stale search results. - Switched `on:keyup` to `on:input` for robust input handling. Co-authored-by: Yeboster <23556525+Yeboster@users.noreply.github.com> --- .jules/bolt.md | 3 +++ src/routes/DomainSearch.svelte | 13 ++++++++++--- 2 files changed, 13 insertions(+), 3 deletions(-) create mode 100644 .jules/bolt.md diff --git a/.jules/bolt.md b/.jules/bolt.md new file mode 100644 index 0000000..7042b45 --- /dev/null +++ b/.jules/bolt.md @@ -0,0 +1,3 @@ +## 2024-05-23 - Domain Search Race Condition +**Learning:** Asynchronous typeahead searches in SvelteKit must implement a request ID mechanism to discard stale responses. `on:keyup` triggers excessive events and misses some inputs; `on:input` is preferred for correctness and efficiency. +**Action:** Always wrap async search handlers with a request ID check and use `on:input` for text fields. diff --git a/src/routes/DomainSearch.svelte b/src/routes/DomainSearch.svelte index 2cde1b3..17a6859 100644 --- a/src/routes/DomainSearch.svelte +++ b/src/routes/DomainSearch.svelte @@ -16,6 +16,7 @@ let nameSearched: string = ''; let isLoading: boolean = false; let debounceTimer: NodeJS.Timeout; + let lastRequestId = 0; $: errors = invalid ? validator.getErrors() : []; $: invalid = domainName !== '' && !validator.validate(domainName, { raiseError: false }); @@ -36,12 +37,17 @@ return goto(url); } + // Race condition fix: track the request ID to ensure we only process the latest response + const requestId = ++lastRequestId; nameSearched = domainName.toLocaleLowerCase(); isLoading = true; - domain = await $metaNamesSdk.domainRepository.find(domainName); + const result = await $metaNamesSdk.domainRepository.find(domainName); - isLoading = false; + if (requestId === lastRequestId) { + domain = result; + isLoading = false; + } } async function submit() { @@ -51,11 +57,12 @@