Skip to content

Debounce component search input#2433

Open
Mbeaulne wants to merge 1 commit into
06-18-add_client-side_embeddings_cached_in_indexeddbfrom
06-18-fix_search_input_lag
Open

Debounce component search input#2433
Mbeaulne wants to merge 1 commit into
06-18-add_client-side_embeddings_cached_in_indexeddbfrom
06-18-fix_search_input_lag

Conversation

@Mbeaulne

@Mbeaulne Mbeaulne commented Jun 18, 2026

Copy link
Copy Markdown
Collaborator

Description

The component search input now debounces user keystrokes by 200ms before updating the query state used for lexical search and AI search. A new DebouncedComponentSearchInput component manages its own local input value and only commits to the parent after the debounce delay, preventing expensive lexical search operations from running on every keystroke. useDeferredValue is applied to the committed query so that React can deprioritize the search re-renders, keeping the input responsive. The AI search button is now enabled only after the debounced query has settled, and the test has been updated to wait for that enabled state before clicking.

Related Issue and Pull requests

Type of Change

  • Bug fix
  • New feature
  • Improvement
  • Cleanup/Refactor
  • Breaking change
  • Documentation update

Checklist

  • I have tested this does not break current pipelines / runs functionality
  • I have tested the changes on staging

Screenshots (if applicable)

Test Instructions

  1. Open the Dashboard Components view.
  2. Type rapidly into the search box and confirm the UI remains responsive without lag on each keystroke.
  3. Pause typing and confirm search results appear after ~200ms.
  4. Verify the AI search button only becomes enabled once the debounced query has committed.
  5. Click AI search and confirm it runs against the expected candidate pool.

Additional Comments

The onCommit callback reference is stabilised via a useRef so the debounce useEffect does not restart its timer when the parent re-renders with a new callback identity.

@github-actions

github-actions Bot commented Jun 18, 2026

Copy link
Copy Markdown

🎩 Preview

A preview build has been created at: 06-18-fix_search_input_lag/609edda

Mbeaulne commented Jun 18, 2026

Copy link
Copy Markdown
Collaborator Author

Warning

This pull request is not mergeable via GitHub because a downstack PR is open. Once all requirements are satisfied, merge this PR as a stack on Graphite.
Learn more

This stack of pull requests is managed by Graphite. Learn more about stacking.

@Mbeaulne Mbeaulne changed the title fix search input lag Debounce component search input Jun 18, 2026
@Mbeaulne Mbeaulne marked this pull request as ready for review June 18, 2026 18:53
@Mbeaulne Mbeaulne requested a review from a team as a code owner June 18, 2026 18:53
@Mbeaulne Mbeaulne force-pushed the 06-18-add_client-side_embeddings_cached_in_indexeddb branch from 60a4a12 to f6d7ea7 Compare June 18, 2026 19:46
@Mbeaulne Mbeaulne force-pushed the 06-18-fix_search_input_lag branch 2 times, most recently from d586cf4 to 89315de Compare June 18, 2026 20:28
@Mbeaulne Mbeaulne force-pushed the 06-18-add_client-side_embeddings_cached_in_indexeddb branch from f6d7ea7 to 27a3952 Compare June 18, 2026 20:28
@Mbeaulne Mbeaulne force-pushed the 06-18-fix_search_input_lag branch from 89315de to 547bdec Compare June 18, 2026 20:49
@Mbeaulne Mbeaulne force-pushed the 06-18-add_client-side_embeddings_cached_in_indexeddb branch 2 times, most recently from 316495b to 89c4999 Compare June 18, 2026 21:02
@Mbeaulne Mbeaulne force-pushed the 06-18-fix_search_input_lag branch 2 times, most recently from 4a1f6c8 to ba5f48a Compare June 18, 2026 21:16
@Mbeaulne Mbeaulne force-pushed the 06-18-add_client-side_embeddings_cached_in_indexeddb branch from 89c4999 to 92a80e1 Compare June 18, 2026 21:16
@camielvs

Copy link
Copy Markdown
Collaborator

🤖 Code review — Debounce component search input

Small, sensible perf fix for the top of the stack — by #2432 every keystroke could trigger IDF scoring (#2426), fuzzy Levenshtein (#2427), and embedding work, so gating input is well-justified. The DebouncedComponentSearchInput implementation is clean: the onCommitRef pattern keeps the latest callback without resetting the 200ms timer, the cleanup is correct, the aria-label is preserved, and updating the test to await the button becoming enabled is the right adjustment.

Findings:

  • Debounce + useDeferredValue together looks redundant. This PR introduces both: a 200ms debounce inside the new input component and useDeferredValue(query) in the parent. But the input is now a decoupled child with its own local state, so the parent's query only changes every 200ms and there's no longer a fast-updating controlled input for useDeferredValue to keep responsive. The net effect of the deferred layer here is mostly an extra frame of staleness on top of the debounce. I'd keep one mechanism — the standalone debounced input alone is the simpler choice. If both are deliberate, a one-line comment on what each buys would prevent a future "why two?".

  • Only the Dashboard is debounced; the Editor isn't. ComponentSearchV2Content still uses immediate onChange + useDeferredValue. Given the branch name (fix_search_input_lag) and that the same heavy per-keystroke search runs in both surfaces, was leaving the Editor out intentional? If the lag affects both, the Editor would benefit from the same treatment (and it'd be a natural place to share the DebouncedComponentSearchInput component rather than duplicating later).

  • Minor — input is no longer parent-controllable. Moving the value into child local state means the parent can't programmatically set/clear the query anymore. Nothing does that today, so it's fine, but worth noting if a "clear search" affordance is ever added. Also an initial empty onCommit("") fires ~200ms after mount — harmless no-op.

  • Minor — slight staleness on the AI-search click path. trimmedQuery now derives from deferredQuery and is read by startAiSearch; under load a click could momentarily act on a marginally stale query. The test's waitFor covers it; real-world risk is low.

Overall good to go once the debounce-vs-deferred intent is clarified.

@Mbeaulne Mbeaulne force-pushed the 06-18-fix_search_input_lag branch from ba5f48a to fd4ebef Compare June 22, 2026 16:55
@Mbeaulne Mbeaulne force-pushed the 06-18-add_client-side_embeddings_cached_in_indexeddb branch from 92a80e1 to f8d7d77 Compare June 22, 2026 16:55
@Mbeaulne Mbeaulne force-pushed the 06-18-fix_search_input_lag branch from fd4ebef to 04159ac Compare June 22, 2026 17:38
@Mbeaulne Mbeaulne force-pushed the 06-18-add_client-side_embeddings_cached_in_indexeddb branch from f8d7d77 to 1a2ae6e Compare June 22, 2026 17:38
@Mbeaulne Mbeaulne force-pushed the 06-18-add_client-side_embeddings_cached_in_indexeddb branch from 03c9fa8 to f23785c Compare June 22, 2026 19:32
@Mbeaulne Mbeaulne force-pushed the 06-18-fix_search_input_lag branch from bcaf99b to 23f25da Compare June 22, 2026 19:32
Comment thread src/routes/Dashboard/DashboardComponentsV2View.tsx
Comment thread src/routes/Dashboard/DashboardComponentsV2View.tsx Outdated
Comment thread src/routes/Dashboard/DashboardComponentsV2View.tsx Outdated
@Mbeaulne Mbeaulne force-pushed the 06-18-fix_search_input_lag branch from 23f25da to b790697 Compare June 22, 2026 19:58
@Mbeaulne Mbeaulne force-pushed the 06-18-add_client-side_embeddings_cached_in_indexeddb branch from f23785c to 4d1b974 Compare June 24, 2026 18:11
@Mbeaulne Mbeaulne force-pushed the 06-18-fix_search_input_lag branch from b790697 to 149103e Compare June 24, 2026 18:11
@Mbeaulne Mbeaulne force-pushed the 06-18-add_client-side_embeddings_cached_in_indexeddb branch from 4d1b974 to 7f152b7 Compare June 24, 2026 19:52
@Mbeaulne Mbeaulne force-pushed the 06-18-fix_search_input_lag branch 2 times, most recently from 79faaaa to a6ad948 Compare June 25, 2026 15:55
@Mbeaulne Mbeaulne force-pushed the 06-18-add_client-side_embeddings_cached_in_indexeddb branch from 7f152b7 to a48133d Compare June 25, 2026 15:55
@Mbeaulne Mbeaulne force-pushed the 06-18-fix_search_input_lag branch from a6ad948 to ca20ec6 Compare June 25, 2026 19:38
@Mbeaulne Mbeaulne force-pushed the 06-18-fix_search_input_lag branch from ca20ec6 to 609edda Compare June 25, 2026 19:43
Comment thread src/routes/v2/pages/Editor/components/ComponentSearchV2Content.tsx
Comment thread src/routes/Dashboard/DashboardComponentsV2View.tsx
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.

3 participants