Skip to content

Fix dropped keystrokes and lag in plugin search - #4102

Merged
SawyerHood merged 1 commit into
mainfrom
bb/fix-plugin-search-input-functionality-thr_ejj4wsiu7n
Sep 22, 2026
Merged

SawyerHood merged 1 commit into
mainfrom
bb/fix-plugin-search-input-functionality-thr_ejj4wsiu7n

Conversation

@SawyerHood

Copy link
Copy Markdown
Collaborator

Human comments

What was wrong

The plugin search input was controlled directly by the URL query param (since #2941). React Router 7 applies every navigation inside startTransition, so after each keystroke React restored the controlled input to the stale URL value before the navigation landed. Typing "terminal notes" quickly produced t ntes / tal otes. Each keystroke also re-rendered the whole browse route. Since #3644, the first keystroke swapped the shelves for an unpaginated grid of the full catalog (~270 cards), and clearing the query rebuilt ~100 shelf cards in one blocking task.

What changed

  • PluginBrowseControls.tsx: PluginCollectionToolbar keeps a local search draft. It writes the URL 200 ms after typing stops; clearing writes immediately. Incoming URL values are adopted only when they are not one of the toolbar's own in-flight writes, so a lagging navigation cannot overwrite newer typing. Back/forward still updates the input. This applies to the Browse, Installed, and Author views.
  • BrowsePluginsTab.tsx, PluginAuthorPage.tsx: drop the second 300 ms useDebouncedValue. The URL value is already debounced.
  • PluginCatalogCard.tsx: PluginCatalogGrid renders RESOURCE_GRID_PAGE_SIZE cards at a time with ResourceInfiniteScrollSentinel, like the Installed list.
  • BrowsePluginsTab.tsx: shelves are built from the unfiltered catalog and stay mounted with the hidden attribute while a search is active. Clearing the query no longer remounts them. <Activity> was measured too; it re-runs every card's mount effects (Radix Tooltip/Avatar) on reveal and was about 2× slower than hidden.

Known edge: pressing back within 200 ms of typing can let the pending write re-apply the typed query.

How you verified

  • New tests, each shown to fail on the code before its fix and pass after:

    • BrowsePluginsTab.test.tsx "keeps every keystroke while the URL query catches up": dispatches native input events outside act, as real keystrokes arrive. The old code reverts the first keystroke to ''.
    • BrowsePluginsTab.test.tsx "renders search results a page at a time": the old code rendered 30 cards instead of 12.
    • BrowsePluginsTab.test.tsx "keeps the shelves mounted while a search is active": the previous version rebuilt the shelves element.
    • PluginBrowseControls.test.tsx "keeps typed text while the URL query lags behind": an earlier draft of this fix reverted to Memory.
  • Existing tests that asserted the URL synchronously after fireEvent.change now wait for the debounced write.

  • vitest run src/components/plugin src/views/ToolsView.plugin-detail.test.tsx: 54 files, 568 tests pass.

  • turbo run typecheck lint --filter=@bb/app: passes.

  • Live dev app (headless Chromium, Event Timing + Long Tasks APIs). Typing "terminal notes" at 60 ms/key:

    Before After
    Resulting value t ntes / tal otes terminal notes
    Long tasks per run 5 (max ~530 ms) 0
    Slowest keystroke to paint 728–760 ms 16–32 ms

    Backspacing to empty, alternating versions in the same session: worst long task 319–389 ms → 63–64 ms. Search results, infinite scroll (24 → 96 cards), and clearing back to the shelves all work.

AGENT GENERATED

🤖 Generated with Claude Code

The plugin search input was controlled directly by the URL query param.
React Router 7 applies navigations in startTransition, so React restored
the input to the stale value between keystrokes (typing "terminal notes"
produced "t ntes"), and every keystroke re-rendered the whole browse page,
including an unpaginated grid of the full catalog.

- PluginCollectionToolbar keeps a local draft and writes the URL 200 ms
  after typing stops (clearing writes immediately). Incoming URL values
  that match in-flight writes are ignored, so a lagging navigation cannot
  overwrite newer typing.
- Browse and author tabs drop their second 300 ms debounce.
- PluginCatalogGrid renders a page at a time with infinite scroll.
- Browse shelves stay mounted (hidden) during a search, so clearing the
  query no longer rebuilds ~100 shelf cards.

Co-Authored-By: Claude Opus 5.5 (1M context) <[email protected]>
@SawyerHood
SawyerHood merged commit 4c42240 into main Sep 22, 2026
16 checks passed
@SawyerHood
SawyerHood deleted the bb/fix-plugin-search-input-functionality-thr_ejj4wsiu7n branch September 22, 2026 23:47
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.

1 participant