Cache search index in query and show skeleton while typing#2471
Conversation
🎩 PreviewA preview build has been created at: |
94bf16a to
905bce9
Compare
2e4cdd9 to
2c11f71
Compare
2c11f71 to
f84f5fb
Compare
9db5c6e to
c547aec
Compare
c547aec to
7c40739
Compare
f84f5fb to
7d9f4e2
Compare
7d9f4e2 to
370138a
Compare
7c40739 to
cdd3ff0
Compare
84aa8ca to
dbf3739
Compare
dbf3739 to
7590eab
Compare
| }); | ||
|
|
||
| const handleQueryCommit = (value: string) => { | ||
| startSearchTransition(() => setQuery(value)); | ||
| startSearchTransition(() => { | ||
| setQuery(value); | ||
| setIsSearching(false); | ||
| }); | ||
| }; | ||
|
|
||
| const handleSuggestedSearch = (value: string) => { | ||
| setLocalQuery(value); | ||
| startSearchTransition(() => setQuery(value)); | ||
| startSearchTransition(() => { | ||
| setQuery(value); | ||
| setIsSearching(false); | ||
| }); |
There was a problem hiding this comment.
Race condition: isSearching state can be incorrectly cleared
Same race condition as in DashboardComponentsV2View. When rapid typing occurs, setIsSearching(false) in the transition callback can execute after new input has been entered, causing the skeleton to disappear prematurely.
This component uses a debounced input component, so the race window may be even wider since there's both debouncing and transition timing involved.
Fix: The callbacks need to verify the current input value before clearing isSearching. Since this component uses DebouncedComponentSearchInput, you'll need to either:
- Pass a ref to access the current input value, or
- Track the expected committed value and only clear
isSearchingwhen it matches
const [expectedCommit, setExpectedCommit] = useState("");
const handleQueryCommit = (value: string) => {
setExpectedCommit(value);
startSearchTransition(() => {
setQuery(value);
setIsSearching(false);
});
};
const handleLocalQueryChange = (value: string) => {
setIsSearching(value.trim() !== expectedCommit.trim());
};Spotted by Graphite
Is this helpful? React 👍 or 👎 to let us know.
7590eab to
f306696
Compare
|
I'm not seeing any loading states on local or Prod: local |
camielvs
left a comment
There was a problem hiding this comment.
Issue appears to be on master branch, not this PR
f306696 to
29023ff
Compare


Description
Improves search responsiveness by showing a skeleton loading state immediately when the user starts typing, preventing the UI from performing expensive sorting and searching operations on keystrokes that haven't yet committed to a query transition.
A new
isSearchingflag is set as soon as the local input value diverges from the committed query. WhileisSearchingis true, the active query is treated as empty, sorted index computation is skipped, and the results area renders a skeleton. Once the debounced commit fires,isSearchingis cleared and the real results appear.The
pauseSearchoption is threaded intouseComponentSearchV2Stateso the editor-side component search panel gets the same behaviour.The hydration query now builds and caches the search index (
IndexEntry[]) alongside the hydrated references, so expensive index derivation is tied to the library fingerprint cache rather than recomputed on every render. The library fingerprint now includes source kind, id, and label so cache entries correctly invalidate when the source set changes.Pre-computed token and phrase caches (
searchableTokens,searchablePhrases) are stored on eachIndexEntryat index-build time, eliminating repeated tokenization and regex work on every keystroke insidescoreEntry.Search suggestions are now only computed when there are no lexical or collection matches and rerank is not active, avoiding unnecessary work when results are already present.
Related Issue and Pull requests
Type of Change
Checklist
Screenshots (if applicable)
Test Instructions
Additional Comments
The
buildSourcedHydratedReferenceshelper is no longer needed and has been removed. The hydration query now pairs each hydrated reference with its source directly, making the post-hydration join step unnecessary.