Skip to content

Commit 58bd8c2

Browse files
committed
Avoid race condition
1 parent bf37c06 commit 58bd8c2

File tree

1 file changed

+3
-1
lines changed

1 file changed

+3
-1
lines changed

module/source/hooks/use-unity-loader.ts

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -70,7 +70,6 @@ const useUnityLoader = (unityConfig: UnityConfig): UnityLoaderStatus => {
7070
script.src = loaderUrl;
7171
script.async = true;
7272
script.setAttribute("data-status", "loading");
73-
document.body.appendChild(script);
7473

7574
// Define load handler.
7675
const handleLoad = () => {
@@ -98,6 +97,9 @@ const useUnityLoader = (unityConfig: UnityConfig): UnityLoaderStatus => {
9897
script.addEventListener("load", handleLoad);
9998
script.addEventListener("error", handleError);
10099

100+
// Append the script to the document body.
101+
document.body.appendChild(script);
102+
101103
// Initialize the reference map.
102104
scriptReferenceMap.set(loaderUrl, {
103105
count: 1,

0 commit comments

Comments
 (0)