File tree Expand file tree Collapse file tree 1 file changed +20
-0
lines changed
docusaurus-search-local/src/client/theme/SearchBar Expand file tree Collapse file tree 1 file changed +20
-0
lines changed Original file line number Diff line number Diff line change @@ -387,6 +387,26 @@ export default function SearchBar({
387387 )
388388 : false ;
389389
390+ // Sync the input value and focus state for SSR
391+ useEffect (
392+ ( ) => {
393+ const searchBar = searchBarRef . current ;
394+ const domValue = searchBar ?. value ;
395+ if ( domValue ) {
396+ setInputValue ( domValue ) ;
397+ }
398+ if ( searchBar && document . activeElement === searchBar ) {
399+ focusAfterIndexLoaded . current = true ;
400+ loadIndex ( ) ;
401+ setFocused ( true ) ;
402+ handleSearchBarToggle ?.( true ) ;
403+ }
404+ } ,
405+ // Only run this effect on mount
406+ // eslint-disable-next-line react-hooks/exhaustive-deps
407+ [ ]
408+ ) ;
409+
390410 useEffect ( ( ) => {
391411 if ( ! searchBarShortcut ) {
392412 return ;
You can’t perform that action at this time.
0 commit comments