feat(onboarding): truly cancel superseded starter-site searches#474
Merged
Conversation
The debounced LLM search already waited and ignored stale responses via an `active` flag, but a superseded in-flight request still ran to completion on the backend. Add a per-request AbortController and abort it in the effect cleanup, so a new keystroke drops the prior LLM call rather than only discarding its result — less wasted backend work, no flicker. - rest.js: thread an optional AbortSignal through get() -> requestData() -> fetch. - SiteList.js: per-request AbortController, abort() on cleanup; AbortError is swallowed so an intentional cancel doesn't trip the Fuse fallback. - Extract SEARCH_DEBOUNCE_MS / SEARCH_MIN_CHARS; bump debounce 600ms -> 700ms so the search waits until typing has more confidently settled. Min chars stays 3. - Tidy a pre-existing `let safety` -> `const` in the personalization effect (lint). Verified: lint clean, onboarding build compiles, and an 18-assertion mechanism test (real rest.js get() + faithful effect control-flow) covering the debounce, 3-char gate, true abort-on-supersede, no-false-fallback, and stale-response guard. Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_01WFjBhjkmFUmVgK9iTNXZRw
Collaborator
HardeepAsrani
approved these changes
Jun 19, 2026
Collaborator
|
🎉 This PR is included in version 1.4.0 🎉 The release is available on GitHub release Your semantic-release bot 📦🚀 |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
What & why
The onboarding starter-site search (LLM-ranked) already debounced and ignored stale responses via an
activeflag — but a superseded in-flight request still ran to completion on the backend. Typingmed → medica → medicalcould leave earlier requests churning on the AI proxy even though their results were thrown away.This adds true cancellation: each debounced request gets its own
AbortController, and the effect cleanup callsabort()— so a new keystroke (or editor switch) drops the prior LLM call instead of just discarding its result. Less wasted backend work, no late-result flicker.Changes
onboarding/src/utils/rest.js— thread an optionalAbortSignalthroughget()→requestData()→fetch(options.signal). Inert when omitted (back-compat for all other callers).onboarding/src/Components/Steps/SiteList.jsAbortController;controller.abort()in the search effect's cleanup..catchswallowsAbortErrorso an intentional cancel does not flipsearchFailed(which would spuriously trigger the Fuse fallback). Genuine errors / 404 / hang / empty still fall back as before.SEARCH_DEBOUNCE_MS/SEARCH_MIN_CHARSconstants. Debounce bumped 600ms → 700ms so the search waits until typing has more confidently settled (still in the 500–800ms range). Min chars stays 3 (preserves real short niches: spa, gym, law, art, vet…).let safety→const safetyin the personalization effect (clears the lintprefer-const).Base
Branched off
development(identical to releasedmaster1.3.0 for these files). The debounce/min-chars themselves already shipped in 1.3.0 — this PR is the missing cancellation piece plus the tuning.Verification
wp-scripts lint-js— 0 errors, 0 warningswp-scripts build onboarding— compilesrest.jsget()signal threading + faithful reproduction of the search effect's control flow — debounce collapses rapid keystrokes to one request, 3-char gate, true abort on supersede, abort doesn't trip the fallback, success/empty/error paths, stale-response guard.whatwg-fetchunused; no microtask race; no safety-timer leak; no TDZ on theconstchange).🤖 Generated with Claude Code