Astrabit-ST / Luminol

An RPG Maker XP-VX Ace rewrite, written in Rust with love 💕
https://luminol.dev/
GNU General Public License v3.0
95 stars 11 forks source link

fix(web): send WebAssembly module to web worker instead of refetching #111

Closed white-axe closed 4 months ago

white-axe commented 4 months ago

Description The web build is supposed to be usable with no Internet connection once the user has visited the page once because it caches itself in the user's browser. However, in my testing, the web build doesn't seem to work in Firefox when not connected to the Internet (like when using airplane mode) or when "Work Offline" in the F10 menu is enabled. This applies even if the web build is being served over localhost, on the same computer that Firefox is running on!

I traced the error to the wasm_bindgen() function in main.js and worker.js, inside which a fetch() call is used to fetch the WebAssembly module. For some reason, when using Firefox while offline, the fetch() call works fine in main.js (on the main thread) but always fails in worker.js (on the worker thread). I'm not sure why it's failing, but the fact that it fails even when serving over localhost makes me suspect it's a Firefox bug.

To work around this, the WebAssembly module is now fetched only in main.js and then cloned and sent to the web worker where it can be used without having to fetch it a second time.

Testing The web build should now work with airplane mode turned on in Chromium-based browsers as well as Firefox.

Checklist