From bb4ae8e82dfee2f089f57c8f359cc378a1a6aa85 Mon Sep 17 00:00:00 2001 From: Akim Mamedov Date: Sat, 16 Dec 2023 01:24:54 +0700 Subject: [PATCH] Reproduce bug --- packages/core/js-client/src/marine/loader.ts | 36 ++++++++++++-------- packages/core/js-client/vite.config.ts | 15 -------- 2 files changed, 22 insertions(+), 29 deletions(-) diff --git a/packages/core/js-client/src/marine/loader.ts b/packages/core/js-client/src/marine/loader.ts index 1c64042f..184e4935 100644 --- a/packages/core/js-client/src/marine/loader.ts +++ b/packages/core/js-client/src/marine/loader.ts @@ -27,21 +27,29 @@ type StrategyReturnType = [ export const loadMarineDeps = async ( CDNUrl: string, ): Promise => { - const [marineJsWasm, avmWasm] = await Promise.all([ - fetchResource( - "@fluencelabs/marine-js", - "/dist/marine-js.wasm", - CDNUrl, - ).then((res) => { - return res.arrayBuffer(); - }), - fetchResource("@fluencelabs/avm", "/dist/avm.wasm", CDNUrl).then((res) => { - return res.arrayBuffer(); - }), - ]); + const timeout = new Promise((resolve) => { + setTimeout(resolve, 500); + }); - // TODO: load worker in parallel with avm and marine, test that it works - const worker = await getWorker("@fluencelabs/marine-worker", CDNUrl); + const [marineJsWasm, avmWasm, worker] = await Promise.all([ + timeout.then(() => { + return fetchResource( + "@fluencelabs/marine-js", + "/dist/marine-js.wasm", + CDNUrl, + ).then((res) => { + return res.arrayBuffer(); + }); + }), + timeout.then(() => { + return fetchResource("@fluencelabs/avm", "/dist/avm.wasm", CDNUrl).then( + (res) => { + return res.arrayBuffer(); + }, + ); + }), + getWorker("@fluencelabs/marine-worker", CDNUrl), + ]); return [marineJsWasm, avmWasm, worker]; }; diff --git a/packages/core/js-client/vite.config.ts b/packages/core/js-client/vite.config.ts index 08eef44f..6afe3ee3 100644 --- a/packages/core/js-client/vite.config.ts +++ b/packages/core/js-client/vite.config.ts @@ -14,16 +14,10 @@ * limitations under the License. */ -import { createRequire } from "module"; - -import inject from "@rollup/plugin-inject"; import { transform } from "esbuild"; import { PluginOption, UserConfig } from "vite"; import tsconfigPaths from "vite-tsconfig-paths"; -const require = createRequire(import.meta.url); -const esbuildShim = require.resolve("node-stdlib-browser/helpers/esbuild/shim"); - function minifyEs(): PluginOption { return { name: "minifyEs", @@ -56,15 +50,6 @@ const config: UserConfig = { formats: ["es"], }, outDir: "./dist/browser", - rollupOptions: { - plugins: [ - inject({ - global: [esbuildShim, "global"], - process: [esbuildShim, "process"], - Buffer: [esbuildShim, "Buffer"], - }), - ], - }, }, plugins: [tsconfigPaths(), minifyEs()], optimizeDeps: {