fix(web): send WebAssembly module to web worker instead of refetching #111
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
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 afetch()
call is used to fetch the WebAssembly module. For some reason, when using Firefox while offline, thefetch()
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
cargo fmt
.cargo clippy
. If applicable, add:--target wasm32-unknown-unknown
cargo build --release
trunk build --release