From 9cd1e1d5a6556550d9f3f0b49f792f3447d04ded Mon Sep 17 00:00:00 2001 From: Noy <59097122+noyyyy@users.noreply.github.com> Date: Sat, 19 Oct 2024 16:32:59 +0800 Subject: [PATCH] fix: remove network check on refresh --- packages/client/src/ui/hooks/useCheckNetworkHealth.ts | 9 +++++++++ packages/client/src/ui/hooks/useControlGameEnd.ts | 8 ++++++++ 2 files changed, 17 insertions(+) diff --git a/packages/client/src/ui/hooks/useCheckNetworkHealth.ts b/packages/client/src/ui/hooks/useCheckNetworkHealth.ts index 6286115..63e1367 100644 --- a/packages/client/src/ui/hooks/useCheckNetworkHealth.ts +++ b/packages/client/src/ui/hooks/useCheckNetworkHealth.ts @@ -6,7 +6,10 @@ export function useCheckNetworkHealth() { const errorHandler = (event: ErrorEvent): void => { logDebug("Global error:", event.error); + logDebug("readyState: ", document.readyState); + if ( + document.readyState !== "loading" && event.error && (event.error.toString().includes("RuntimeError: unreachable") || event.error @@ -18,10 +21,16 @@ export function useCheckNetworkHealth() { } }; + const beforeReloadHandler = (): void => { + window.removeEventListener("error", errorHandler); + }; + window.addEventListener("error", errorHandler); + window.addEventListener("beforeunload", beforeReloadHandler); return () => { window.removeEventListener("error", errorHandler); + window.removeEventListener("beforeunload", beforeReloadHandler); }; }, []); diff --git a/packages/client/src/ui/hooks/useControlGameEnd.ts b/packages/client/src/ui/hooks/useControlGameEnd.ts index e5c6444..ec616f4 100644 --- a/packages/client/src/ui/hooks/useControlGameEnd.ts +++ b/packages/client/src/ui/hooks/useControlGameEnd.ts @@ -4,6 +4,7 @@ import { zeroEntity } from "../../utils"; import { getEntityIdFromKeys } from "@dojoengine/utils"; import { useEffect, useMemo } from "react"; import { ShowItem, useUIStore } from "../../store"; +import { logDebug } from "../lib/utils"; export function useGameEnd() { const { @@ -19,6 +20,13 @@ export function useGameEnd() { getEntityIdFromKeys([BigInt(s?.currentMatch ?? 0)]) ); + logDebug( + "check player in match and game end", + playerValue, + s?.currentMatch, + result + ); + const end = useMemo(() => { let e = false;