Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

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

Merged
merged 1 commit into from
Feb 22, 2024

Conversation

white-axe
Copy link
Collaborator

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

  • Run cargo fmt.
  • Run cargo clippy. If applicable, add:
    • --target wasm32-unknown-unknown
  • Run cargo build --release
  • If applicable, run trunk build --release

@melody-rs melody-rs merged commit 490d4e4 into Astrabit-ST:dev Feb 22, 2024
5 checks passed
@white-axe white-axe deleted the firefox-offline-fix branch February 22, 2024 14:44
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants