Skip to content

fix(search): prevent submissions while the prompt is loading - #2291

Merged
SBoudrias merged 1 commit into
SBoudrias:mainfrom
imharjot:fix-search-stale-selection
Oct 4, 2026
Merged

SBoudrias merged 1 commit into
SBoudrias:mainfrom
imharjot:fix-search-stale-selection

Conversation

@imharjot

@imharjot imharjot commented Oct 4, 2026

Copy link
Copy Markdown
Contributor

Pressing Enter while an async search is still loading could submit a choice from the previous query. A prompt showing Alberta would return Alberta after typing Que and pressing Enter before the Quebec results arrived. Repeated Enter presses could also run an async validator more than once.

Only submit a selected choice when the prompt is idle. While it is busy, the existing fallback restores the search term after readline clears it, so typing can continue without losing the query.

Added regressions through the public prompt test interface for stale results, keeping the query after an early Enter, and repeated Enter during validation. A standalone Node reproduction also returned Alberta on unchanged source and Quebec with the fix.

Fixes #2290

Terminal reproduction: https://gist.github.com/imharjot/72b8987f390e679008abff6f185f508a

Validation on Node 24.11.1 with Yarn 4.18.1:

  • yarn pretest
  • TERM=xterm-256color yarn test — 436 unit tests passed, one existing skip; CJS 5/5 and ESM 7/7
  • TERM=xterm-256color yarn vitest --run --coverage
  • yarn package lint --check
  • yarn setup — no changes to the reviewed patch

The normal terminal setting is needed by the legacy i18n test wrapper for simulated backspaces. With TERM=dumb, four localized confirm retry tests also time out on unchanged upstream source.

@codecov

codecov Bot commented Oct 4, 2026 •

Copy link
Copy Markdown

Codecov Report

✅ All modified and coverable lines are covered by tests.
⚠️ Please upload report for BASE (main@73b5eab). Learn more about missing BASE report.

Additional details and impacted files
@@           Coverage Diff           @@
##             main    #2291   +/-   ##
=======================================
  Coverage        ?   89.30%           
=======================================
  Files           ?       51           
  Lines           ?     2290           
  Branches        ?      608           
=======================================
  Hits            ?     2045           
  Misses          ?      236           
  Partials        ?        9           

☔ View full report in Codecov by Harness.
📢 Have feedback on the report? Share it here.

🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.
  • 📦 JS Bundle Analysis: Save yourself from yourself by tracking and limiting bundle sizes in JS merges.

Consolidate the regression tests into two flows using withResolver,
exposed from @inquirer/type so all packages can use it until Node 22
becomes the minimum supported version.

Co-authored-by: Simon Boudrias <[email protected]>
@SBoudrias
SBoudrias force-pushed the fix-search-stale-selection branch from 952a3f1 to 1f804ec Compare October 4, 2026 16:57
@SBoudrias

Copy link
Copy Markdown
Owner

Thanks! Good catch!

@SBoudrias
SBoudrias merged commit 7dc77e2 into SBoudrias:main Oct 4, 2026
21 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Search submits stale choices while a new query is loading

2 participants