From ea30505e52dd90c8e3c5d3860ec22ed46fbe399c Mon Sep 17 00:00:00 2001 From: Alexander Hjorth Date: Tue, 25 Feb 2025 16:39:43 +0100 Subject: [PATCH 1/3] script remove --- module/source/hooks/use-unity-loader.ts | 16 +++++++++++++--- 1 file changed, 13 insertions(+), 3 deletions(-) diff --git a/module/source/hooks/use-unity-loader.ts b/module/source/hooks/use-unity-loader.ts index 8fd574ff..f2b9023d 100644 --- a/module/source/hooks/use-unity-loader.ts +++ b/module/source/hooks/use-unity-loader.ts @@ -3,6 +3,16 @@ import { isBrowserEnvironment } from "../constants/is-browser-environment"; import { UnityLoaderStatus } from "../enums/unity-loader-status"; import { UnityConfig } from "../exports"; +interface ScriptData { + count: number; + status: UnityLoaderStatus; + handleLoad?: () => void; + handleError?: () => void; +} + +// Map to track script references, status, and event handlers. +const scriptReferenceMap = new Map(); + /** * Hook to embed a Unity Loader script. * @param source The source of the unity loader. @@ -18,12 +28,12 @@ const useUnityLoader = (unityConfig: UnityConfig): UnityLoaderStatus => { // this scenario, the window is not available. We can't create a Unity // Loader in this case. if (isBrowserEnvironment === false) { - return; + return undefined; } // If the script's source is null, we'll reset the status to idle. if (unityConfig.loaderUrl === null) { setStatus(UnityLoaderStatus.Idle); - return; + return undefined; } /** * Find existing script element by source. It may have been added by @@ -78,7 +88,7 @@ const useUnityLoader = (unityConfig: UnityConfig): UnityLoaderStatus => { if (script !== null) { script.removeEventListener("load", setStateFromEvent); script.removeEventListener("error", setStateFromEvent); - window.document.body.removeChild(script); + script.remove(); } }; }, [unityConfig.loaderUrl]); From e74ceb3e33960d20c59cc9022a07adae1b9d6813 Mon Sep 17 00:00:00 2001 From: Alexander Hjorth Date: Wed, 26 Feb 2025 11:57:11 +0100 Subject: [PATCH 2/3] remove old oops --- module/source/hooks/use-unity-loader.ts | 16 +++------------- 1 file changed, 3 insertions(+), 13 deletions(-) diff --git a/module/source/hooks/use-unity-loader.ts b/module/source/hooks/use-unity-loader.ts index f2b9023d..8fd574ff 100644 --- a/module/source/hooks/use-unity-loader.ts +++ b/module/source/hooks/use-unity-loader.ts @@ -3,16 +3,6 @@ import { isBrowserEnvironment } from "../constants/is-browser-environment"; import { UnityLoaderStatus } from "../enums/unity-loader-status"; import { UnityConfig } from "../exports"; -interface ScriptData { - count: number; - status: UnityLoaderStatus; - handleLoad?: () => void; - handleError?: () => void; -} - -// Map to track script references, status, and event handlers. -const scriptReferenceMap = new Map(); - /** * Hook to embed a Unity Loader script. * @param source The source of the unity loader. @@ -28,12 +18,12 @@ const useUnityLoader = (unityConfig: UnityConfig): UnityLoaderStatus => { // this scenario, the window is not available. We can't create a Unity // Loader in this case. if (isBrowserEnvironment === false) { - return undefined; + return; } // If the script's source is null, we'll reset the status to idle. if (unityConfig.loaderUrl === null) { setStatus(UnityLoaderStatus.Idle); - return undefined; + return; } /** * Find existing script element by source. It may have been added by @@ -88,7 +78,7 @@ const useUnityLoader = (unityConfig: UnityConfig): UnityLoaderStatus => { if (script !== null) { script.removeEventListener("load", setStateFromEvent); script.removeEventListener("error", setStateFromEvent); - script.remove(); + window.document.body.removeChild(script); } }; }, [unityConfig.loaderUrl]); From 91235fa155a1dfd191858712438cc3afe64000a9 Mon Sep 17 00:00:00 2001 From: Alexander Hjorth Date: Wed, 26 Feb 2025 11:57:53 +0100 Subject: [PATCH 3/3] fix --- module/source/hooks/use-unity-loader.ts | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/module/source/hooks/use-unity-loader.ts b/module/source/hooks/use-unity-loader.ts index 8fd574ff..eb2ad0fa 100644 --- a/module/source/hooks/use-unity-loader.ts +++ b/module/source/hooks/use-unity-loader.ts @@ -18,12 +18,12 @@ const useUnityLoader = (unityConfig: UnityConfig): UnityLoaderStatus => { // this scenario, the window is not available. We can't create a Unity // Loader in this case. if (isBrowserEnvironment === false) { - return; + return undefined; } // If the script's source is null, we'll reset the status to idle. if (unityConfig.loaderUrl === null) { setStatus(UnityLoaderStatus.Idle); - return; + return undefined; } /** * Find existing script element by source. It may have been added by @@ -78,7 +78,7 @@ const useUnityLoader = (unityConfig: UnityConfig): UnityLoaderStatus => { if (script !== null) { script.removeEventListener("load", setStateFromEvent); script.removeEventListener("error", setStateFromEvent); - window.document.body.removeChild(script); + script.remove(); } }; }, [unityConfig.loaderUrl]);