@@ -15,7 +15,13 @@ import {
1515 SpaceBetweenVerticallyIcon ,
1616 TextIcon
1717} from '@radix-ui/react-icons' ;
18- import { Command , Dialog , EmptyState , IconButton } from '@raystack/apsara' ;
18+ import {
19+ Command ,
20+ Dialog ,
21+ EmptyState ,
22+ IconButton ,
23+ Spinner
24+ } from '@raystack/apsara' ;
1925import {
2026 flattenTree ,
2127 type Item as PageItem ,
@@ -106,6 +112,10 @@ export default function DocsSearch({ pageTree }: { pageTree: Root }) {
106112
107113 const trimmedQuery = search . trim ( ) ;
108114 const isSearching = trimmedQuery . length > 0 ;
115+ // While fumadocs debounces + fetches, `query.data` is undefined. Without
116+ // this flag the empty state would flash "No result found" for the duration
117+ // of the request; instead we show a spinner until the fetch settles.
118+ const isLoading = isSearching && query . isLoading ;
109119 const results =
110120 isSearching && query . data && query . data !== 'empty' ? query . data : [ ] ;
111121
@@ -228,14 +238,20 @@ export default function DocsSearch({ pageTree }: { pageTree: Root }) {
228238 ) }
229239 </ div >
230240 < Command . Content className = { styles . searchList } >
231- < Command . Empty className = { styles . searchEmpty } >
232- < EmptyState
233- variant = 'empty1'
234- heading = 'No result found'
235- subHeading = 'The keyword you’re searching for isn’t in the document—try using a different term.'
236- icon = { < ExclamationTriangleIcon /> }
237- />
238- </ Command . Empty >
241+ { isLoading ? (
242+ < div className = { styles . searchLoading } >
243+ < Spinner size = { 5 } aria-label = 'Searching docs' />
244+ </ div >
245+ ) : (
246+ < Command . Empty className = { styles . searchEmpty } >
247+ < EmptyState
248+ variant = 'empty1'
249+ heading = 'No result found'
250+ subHeading = 'The keyword you’re searching for isn’t in the document—try using a different term.'
251+ icon = { < ExclamationTriangleIcon /> }
252+ />
253+ </ Command . Empty >
254+ ) }
239255 { items . map ( ( section , index ) => (
240256 < Fragment key = { section . heading } >
241257 < Command . Group >
0 commit comments