diff --git a/x-pack/plugins/data_enhanced/public/search/ui/connected_search_session_indicator/search_session_tour.tsx b/x-pack/plugins/data_enhanced/public/search/ui/connected_search_session_indicator/search_session_tour.tsx index c090e59b6e9313..8c04410f9953bf 100644 --- a/x-pack/plugins/data_enhanced/public/search/ui/connected_search_session_indicator/search_session_tour.tsx +++ b/x-pack/plugins/data_enhanced/public/search/ui/connected_search_session_indicator/search_session_tour.tsx @@ -35,14 +35,14 @@ export function useSearchSessionTour( if (state === SearchSessionState.Loading) { if (!safeHas(storage, TOUR_TAKING_TOO_LONG_STEP_KEY)) { timeoutHandle = window.setTimeout(() => { - searchSessionIndicatorRef.current?.openPopover(); + safeOpen(searchSessionIndicatorRef); }, TOUR_TAKING_TOO_LONG_TIMEOUT); } } if (state === SearchSessionState.Restored) { if (!safeHas(storage, TOUR_RESTORE_STEP_KEY)) { - searchSessionIndicatorRef.current?.openPopover(); + safeOpen(searchSessionIndicatorRef); } } @@ -79,3 +79,15 @@ function safeSet(storage: IStorageWrapper, key: string) { return true; } } + +function safeOpen(searchSessionIndicatorRef: MutableRefObject) { + if (searchSessionIndicatorRef.current) { + searchSessionIndicatorRef.current.openPopover(); + } else { + // TODO: needed for initial open when component is not rendered yet + // fix after: https://github.com/elastic/eui/issues/4460 + setTimeout(() => { + searchSessionIndicatorRef.current?.openPopover(); + }, 50); + } +}