mirror of
https://github.com/blakeblackshear/frigate.git
synced 2026-04-05 14:47:40 +03:00
Fix mobile back navigation losing overlay state on classification page
This commit is contained in:
parent
0a7c973518
commit
96c40da850
@ -34,7 +34,12 @@ export function useHistoryBack({
|
||||
// Store the current URL (pathname + search, without hash) before pushing history state
|
||||
urlWhenOpenedRef.current =
|
||||
window.location.pathname + window.location.search;
|
||||
window.history.pushState({ overlayOpen: true }, "");
|
||||
// Preserve existing history state (including React Router state) so that
|
||||
// navigating back to this entry doesn't lose location.state values
|
||||
window.history.pushState(
|
||||
{ ...window.history.state, overlayOpen: true },
|
||||
"",
|
||||
);
|
||||
historyPushedRef.current = true;
|
||||
}
|
||||
|
||||
@ -71,4 +76,15 @@ export function useHistoryBack({
|
||||
urlWhenOpenedRef.current = null;
|
||||
}
|
||||
}, [enabled, open]);
|
||||
|
||||
// Clean up stale history entry if the component unmounts while the overlay
|
||||
// is still open (e.g. parent component removed from the tree)
|
||||
React.useEffect(() => {
|
||||
return () => {
|
||||
if (historyPushedRef.current) {
|
||||
historyPushedRef.current = false;
|
||||
window.history.back();
|
||||
}
|
||||
};
|
||||
}, []);
|
||||
}
|
||||
|
||||
Loading…
Reference in New Issue
Block a user