File tree Expand file tree Collapse file tree 2 files changed +9
-6
lines changed Expand file tree Collapse file tree 2 files changed +9
-6
lines changed Original file line number Diff line number Diff line change @@ -5,6 +5,7 @@ import { UseDarkContextProvider } from '../hooks/useDark'
55import { useSearchResult } from '../hooks/useSearch'
66import LoadingBar from '../LoadingBar'
77import SearchProviderMessage from './SearchProviderMessage'
8+ import { useDeferredValue } from 'react'
89
910export const SearchSidebar = ( ) => {
1011 const [ inputValue = '' , setInputValue ] = useLocalStorage (
@@ -19,6 +20,11 @@ export const SearchSidebar = () => {
1920 searching
2021 } = useSearchResult ( inputValue )
2122
23+ // rendering tree is too expensive, useDeferredValue
24+ const groupedByFileSearchResultForRender = useDeferredValue (
25+ groupedByFileSearchResult
26+ )
27+
2228 return (
2329 < UseDarkContextProvider >
2430 < LoadingBar loading = { searching } />
@@ -32,7 +38,7 @@ export const SearchSidebar = () => {
3238 resultCount = { searchCount }
3339 fileCount = { groupedByFileSearchResult . length }
3440 />
35- < SearchResultList matches = { groupedByFileSearchResult } />
41+ < SearchResultList matches = { groupedByFileSearchResultForRender } />
3642 </ UseDarkContextProvider >
3743 )
3844}
Original file line number Diff line number Diff line change 11import type { DisplayResult } from '../postMessage'
22import { childPort } from '../postMessage'
3- import { useCallback , useDeferredValue , useSyncExternalStore } from 'react'
3+ import { useCallback , useSyncExternalStore } from 'react'
44import { useDebounce } from 'react-use'
55
66// id should not overflow, the MOD is large enough
@@ -99,15 +99,12 @@ export const useSearchResult = (inputValue: string) => {
9999 postSearch ( inputValue )
100100 } , [ inputValue ] )
101101
102- // rendering tree is too expensive, useDeferredValue
103- const groupedByFileSearchResult = useDeferredValue ( grouped )
104-
105102 useDebounce ( refreshSearchResult , 100 , [ inputValue ] )
106103
107104 return {
108105 queryInFlight,
109106 searching,
110- groupedByFileSearchResult,
107+ groupedByFileSearchResult : grouped ,
111108 searchCount : grouped . reduce ( ( a , l ) => a + l [ 1 ] . length , 0 ) ,
112109 refreshSearchResult
113110 }
You can’t perform that action at this time.
0 commit comments