fix: cache the wasm runtime so offline actually works - #31
Merged
Conversation
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
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.
Reported from the app: the panel says ~30 MB, pressing descargar ahora leaves 19 MB cached. 19 MB is exactly the models — the WASM runtime was not being stored at all.
Online that is invisible, because the browser just refetches. Offline it is the difference between working and a blank screen, and "funciona sin conexión" is on the front page.
Stop trying to intercept MediaPipe
The service worker was supposed to catch MediaPipe's own WASM fetch via
runtimeCaching. In practice it did not, and rather than guess at why, the app now fetches the engine files itself andcache.puts them into the same cache the service worker reads from. MediaPipe's later request is served from it either way.The bug inside the fix
Warming needs to know which WASM build the browser will pick, since both ship and only one is downloaded. I wrote a SIMD feature-detect probe by hand — and it validated as
falseon Node, which fully supports SIMD.A mis-declared body length made the module malformed, so it reported "no SIMD" everywhere. The fix would have cached the wrong 11 MB build and left the app exactly as broken offline, while looking like it worked. Now using the canonical bytes from
wasm-feature-detect, with a test asserting the probe returns true — because the failure mode is silent and there is nothing else to catch it.Also
report()exposeshasRuntime, and the panel says outright when weights are cached without the runtime.engineUrls()respectsBASE_URL— a leading slash would 404 on Pages, which serves from/esku/.