Explore: Fix new-old-new query history bug (#90214)

* Remove cancelActiveListeners() and delay()

* Wait for handle history to resolve

* Do not sync from URL when state changes

---------

Co-authored-by: harisrozajac <haris.rozajac12@gmail.com>
This commit is contained in:
Piotr Jamróz 2024-07-11 12:37:47 +02:00 committed by GitHub
parent 62494248e3
commit b09798c3fa
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194

View File

@ -20,6 +20,7 @@ export function useStateSync(params: ExploreQueryParams) {
const { location } = useGrafana();
const dispatch = useDispatch();
const panesState = useSelector(selectPanes);
const panesStateRef = useRef(panesState);
const orgId = useSelector((state) => state.user.orgId);
const prevParams = useRef(params);
const initState = useRef<'notstarted' | 'pending' | 'done'>('notstarted');
@ -53,6 +54,10 @@ export function useStateSync(params: ExploreQueryParams) {
return () => unsubscribe();
}, [dispatch, location]);
useEffect(() => {
panesStateRef.current = panesState;
}, [panesState]);
useEffect(() => {
const isURLOutOfSync = prevParams.current?.panes !== params.panes;
@ -74,7 +79,7 @@ export function useStateSync(params: ExploreQueryParams) {
prevParams.current = params;
if (isURLOutOfSync && initState.current === 'done') {
syncFromURL(urlState, panesState, dispatch);
syncFromURL(urlState, panesStateRef.current, dispatch);
}
}, [dispatch, panesState, orgId, location, params, warning]);
}, [dispatch, orgId, location, params, warning]);
}