From 7f15b42d18cf893c2cede1cd52ab4abb1c1d48fb Mon Sep 17 00:00:00 2001 From: momo5502 Date: Wed, 9 Jul 2025 19:09:16 +0200 Subject: [PATCH] Fix loading analyzer and bust caches --- page/public/emulator-worker.js | 14 +++++++++++--- page/src/emulator.ts | 6 +++++- page/src/playground.tsx | 2 ++ 3 files changed, 18 insertions(+), 4 deletions(-) diff --git a/page/public/emulator-worker.js b/page/public/emulator-worker.js index 2e932278..6f2c41ea 100644 --- a/page/public/emulator-worker.js +++ b/page/public/emulator-worker.js @@ -14,6 +14,7 @@ onmessage = async (event) => { payload.options, payload.persist, payload.wasm64, + payload.cacheBuster, ); break; case "event": @@ -70,12 +71,19 @@ function getMessageFromQueue() { return msgQueue.shift(); } -function runEmulation(file, options, persist, wasm64) { +function runEmulation(file, options, persist, wasm64, cacheBuster) { const mainArguments = [...options, "-e", "./root", file]; globalThis.Module = { arguments: mainArguments, noInitialRun: true, + locateFile: (path, scriptDirectory) => { + console.log(path); + console.log(scriptDirectory); + + const bitness = wasm64 ? "64" : "32"; + return `${scriptDirectory}${bitness}/${path}?${cacheBuster}`; + }, onRuntimeInitialized: function () { FS.mkdir("/root"); FS.mount(IDBFS, {}, "/root"); @@ -93,8 +101,8 @@ function runEmulation(file, options, persist, wasm64) { }; if (wasm64) { - importScripts("./64/analyzer.js"); + importScripts("./64/analyzer.js?" + cacheBuster); } else { - importScripts("./32/analyzer.js"); + importScripts("./32/analyzer.js?" + cacheBuster); } } diff --git a/page/src/emulator.ts b/page/src/emulator.ts index 2e8f0427..91e79fdf 100644 --- a/page/src/emulator.ts +++ b/page/src/emulator.ts @@ -76,8 +76,11 @@ export class Emulator { this.terminateReject = reject; }); + const cacheBuster = import.meta.env.VITE_BUILD_TIME || Date.now(); + this.worker = new Worker( - /*new URL('./emulator-worker.js', import.meta.url)*/ "./emulator-worker.js", + /*new URL('./emulator-worker.js', import.meta.url)*/ "./emulator-worker.js?" + + cacheBuster, ); this.worker.onerror = this._onError.bind(this); @@ -93,6 +96,7 @@ export class Emulator { options: translateSettings(settings), persist: settings.persist, wasm64: settings.wasm64, + cacheBuster: import.meta.env.VITE_BUILD_TIME || Date.now(), }, }); } diff --git a/page/src/playground.tsx b/page/src/playground.tsx index 6d80b59f..8ed9ffc1 100644 --- a/page/src/playground.tsx +++ b/page/src/playground.tsx @@ -98,7 +98,9 @@ export class Playground extends React.Component< application: undefined, allowWasm64: false, }; + } + componentDidMount(): void { memory64().then((allowWasm64) => { this.setState({ allowWasm64 }); });