From 09d1cf91e002db1667881648d216a690a0d4f516 Mon Sep 17 00:00:00 2001 From: schroda <50052685+schroda@users.noreply.github.com> Date: Sun, 24 Dec 2023 02:36:09 +0100 Subject: [PATCH] Prevent navigation state update in case path already changed (#511) The fix of e4beafb11f1ee9dd4f464e7d627e40d58dad2115 only worked in dev env and not in prod. This prevents the navigation state update from getting triggered in case the path has changed in the meantime --- src/components/MangaGrid.tsx | 7 +++++++ 1 file changed, 7 insertions(+) diff --git a/src/components/MangaGrid.tsx b/src/components/MangaGrid.tsx index 354775dd..3cdf922b 100644 --- a/src/components/MangaGrid.tsx +++ b/src/components/MangaGrid.tsx @@ -95,8 +95,15 @@ const VerticalGrid = ({ const persistGridStateTimeout = useRef(); const persistGridState = (gridState: GridStateSnapshot) => { + const currentUrl = window.location.href; + clearTimeout(persistGridStateTimeout.current); persistGridStateTimeout.current = setTimeout(() => { + const didLocationChange = currentUrl !== window.location.href; + if (didLocationChange) { + return; + } + navigate( { pathname: '', search: location.search }, { replace: true, state: { ...location.state, snapshot: gridState } },