Skip to content

feat(onboarding): truly cancel superseded starter-site searches#474

Merged
HardeepAsrani merged 1 commit into
developmentfrom
feat/onboarding-search-cancel
Jun 19, 2026
Merged

feat(onboarding): truly cancel superseded starter-site searches#474
HardeepAsrani merged 1 commit into
developmentfrom
feat/onboarding-search-cancel

Conversation

@ineagu

@ineagu ineagu commented Jun 19, 2026

Copy link
Copy Markdown
Contributor

What & why

The onboarding starter-site search (LLM-ranked) already debounced and ignored stale responses via an active flag — but a superseded in-flight request still ran to completion on the backend. Typing med → medica → medical could 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 calls abort() — 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 optional AbortSignal through get()requestData()fetch(options.signal). Inert when omitted (back-compat for all other callers).
  • onboarding/src/Components/Steps/SiteList.js
    • Per-request AbortController; controller.abort() in the search effect's cleanup.
    • .catch swallows AbortError so an intentional cancel does not flip searchFailed (which would spuriously trigger the Fuse fallback). Genuine errors / 404 / hang / empty still fall back as before.
    • Extracted SEARCH_DEBOUNCE_MS / SEARCH_MIN_CHARS constants. 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…).
    • Tidied a pre-existing let safetyconst safety in the personalization effect (clears the lint prefer-const).

Base

Branched off development (identical to released master 1.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 warnings
  • wp-scripts build onboarding — compiles
  • ✅ Mechanism test (18 assertions): real rest.js get() 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.
  • ✅ Adversarial multi-agent review (3 lenses → verify): 6 candidate findings, 0 confirmed real (AbortError classification reliable — native fetch, whatwg-fetch unused; no microtask race; no safety-timer leak; no TDZ on the const change).

🤖 Generated with Claude Code

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
@pirate-bot

Copy link
Copy Markdown
Collaborator

Plugin build for 716946f is ready 🛎️!

@ineagu ineagu requested a review from HardeepAsrani June 19, 2026 11:20
@HardeepAsrani HardeepAsrani merged commit 0e3b2e3 into development Jun 19, 2026
6 of 7 checks passed
@HardeepAsrani HardeepAsrani deleted the feat/onboarding-search-cancel branch June 19, 2026 13:38
@pirate-bot

Copy link
Copy Markdown
Collaborator

🎉 This PR is included in version 1.4.0 🎉

The release is available on GitHub release

Your semantic-release bot 📦🚀

@pirate-bot pirate-bot added the released Indicate that an issue has been resolved and released in a particular version of the product. label Jun 23, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

released Indicate that an issue has been resolved and released in a particular version of the product.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants