fix: make documentation search usable - #9
Merged
Conversation
There was a problem hiding this comment.
Pull request overview
Improves the documentation search dialog interaction so it reliably opens/focuses, handles lazy index loading without stale updates, and surfaces a visible failure state instead of getting stuck loading.
Changes:
- Centralizes “open search” behavior to focus the input for both keyboard shortcuts and trigger clicks.
- Adds a generation/cancellation guard around the async lazy import to prevent stale searches from overwriting newer input.
- Introduces an error state UI when loading/search fails.
Comments suppressed due to low confidence (2)
src/pages/docs/search.tsx:35
- After persisting
searchGenerationin state,runSearchstill uses++searchGenerationand compares againstsearchGenerationas if it were a mutable number. Update the increment/check logic to use the getter/setter (searchGeneration()/setSearchGeneration(...)) so stale async searches cannot clobber newer ones.
const runSearch = async (value: string) => {
const generation = ++searchGeneration;
setQuery(value);
setError(false);
if (!value.trim()) {
src/pages/docs/search.tsx:56
close()currently mutatessearchGenerationdirectly. OncesearchGenerationis stored in component state, increment it via the setter so any in-flight searches see the updated generation and abort correctly.
const close = () => {
searchGeneration += 1;
setOpen(false);
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
Comment on lines
12
to
+15
| const [results, setResults] = state<readonly DocsSearchRecord[]>([]); | ||
| const [error, setError] = state(false); | ||
| let searchGeneration = 0; | ||
|
|
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.
Fixes #8.
The docs search trigger now focuses the input when opened by click as well as keyboard shortcut. Search requests are generation-guarded so stale lazy-index loads cannot overwrite newer input, and failures leave a visible retryable state instead of a permanent loading state.
Validation: