From e3afad74ce7add3590ce3d66852f4e79562f1ee9 Mon Sep 17 00:00:00 2001 From: Steven Date: Thu, 1 Feb 2024 19:27:54 +0800 Subject: [PATCH] fix: update initial wasm --- web/src/App.tsx | 7 +------ web/{public => src}/gomark.wasm | Bin web/src/main.tsx | 28 ++++++++++++++++++---------- 3 files changed, 19 insertions(+), 16 deletions(-) rename web/{public => src}/gomark.wasm (100%) diff --git a/web/src/App.tsx b/web/src/App.tsx index 56242ce26..35fcb974f 100644 --- a/web/src/App.tsx +++ b/web/src/App.tsx @@ -26,11 +26,6 @@ const App = () => { }, [systemStatus.host]); useEffect(() => { - const initialGoWASMExec = async () => { - const go = new window.Go(); - const result = await WebAssembly.instantiateStreaming(fetch("/gomark.wasm"), go.importObject); - go.run(result.instance); - }; const initialState = async () => { try { await userStore.fetchCurrentUser(); @@ -39,7 +34,7 @@ const App = () => { } }; - Promise.all([initialGoWASMExec(), initialState()]).then(() => setLoading(false)); + Promise.all([initialState()]).then(() => setLoading(false)); }, []); useEffect(() => { diff --git a/web/public/gomark.wasm b/web/src/gomark.wasm similarity index 100% rename from web/public/gomark.wasm rename to web/src/gomark.wasm diff --git a/web/src/main.tsx b/web/src/main.tsx index 295dec551..db7ffb4c1 100644 --- a/web/src/main.tsx +++ b/web/src/main.tsx @@ -5,6 +5,7 @@ import { Provider } from "react-redux"; import { RouterProvider } from "react-router-dom"; import "./css/global.css"; import "./css/tailwind.css"; +import wasmUrl from "./gomark.wasm?url"; import "./helpers/polyfill"; import "./i18n"; import "./less/highlight.less"; @@ -12,13 +13,20 @@ import router from "./router"; import store from "./store"; import theme from "./theme"; -const container = document.getElementById("root"); -const root = createRoot(container as HTMLElement); -root.render( - - - - - - , -); +(async () => { + const go = new window.Go(); + const responsePromise = fetch(wasmUrl); + const { instance } = await WebAssembly.instantiateStreaming(responsePromise, go.importObject); + go.run(instance); + + const container = document.getElementById("root"); + const root = createRoot(container as HTMLElement); + root.render( + + + + + + , + ); +})();