From c8f8a86a2bdd43d7eaa6a1b7384b6e7edc29f1df Mon Sep 17 00:00:00 2001 From: RheingoldRiver <18037011+RheingoldRiver@users.noreply.github.com> Date: Fri, 6 Oct 2023 15:56:10 -0500 Subject: [PATCH] better hash-change-aware code --- src/components/GameStateProvider/GameStateProvider.tsx | 8 +------- 1 file changed, 1 insertion(+), 7 deletions(-) diff --git a/src/components/GameStateProvider/GameStateProvider.tsx b/src/components/GameStateProvider/GameStateProvider.tsx index 2bec7ad..839d9a4 100644 --- a/src/components/GameStateProvider/GameStateProvider.tsx +++ b/src/components/GameStateProvider/GameStateProvider.tsx @@ -63,8 +63,6 @@ export default function GameStateProvider({ children }: { children: ReactNode }) const [actionHistory, setActionHistory] = useState([]); const navigate = useNavigate(); - const prevHash = useRef(window.location.hash); - const updateUrl = useRef( debounce((config: Partial) => { const finalConfig = { @@ -74,11 +72,8 @@ export default function GameStateProvider({ children }: { children: ReactNode }) ...config, }; const newHash = serializeUrl(finalConfig); - console.log("New Hash:", newHash); - console.log("Previous Hash:", prevHash.current); - if (newHash === prevHash.current) return; + if (`#/${newHash}` === window.location.hash) return; navigate("/" + newHash); - prevHash.current = newHash; // Update the previous hash }, 250) ); @@ -88,7 +83,6 @@ export default function GameStateProvider({ children }: { children: ReactNode }) useEffect(() => { window.addEventListener("hashchange", function () { - if (window.location.hash === prevHash.current) return; window.location.reload(); }); });