jamsinclair / jSquash

Browser & Web Worker focussed wasm bundles derived from the Squoosh App.
Apache License 2.0
222 stars 14 forks source link

Oxipng multi-threaded mode fails when run from main thread. #31

Closed jamsinclair closed 1 year ago

jamsinclair commented 1 year ago

Describe the bug Oxipng multi threaded code doesn't work when not wrapped in a worker.

This happens due to a known issue with threading solutions with wasm and rust (https://github.com/GoogleChromeLabs/wasm-bindgen-rayon#caveats).

To Reproduce Steps to reproduce the behavior:

  1. Copy the with-vite example
  2. Modify the code to import and use oxipng in the main js script
  3. Set in the development server the following headers:
    headers: {
    "Cross-Origin-Opener-Policy": "same-origin",
    "Cross-Origin-Embedder-Policy": "require-corp",
    }

Expected behavior

We should update our wrapper code to not run multi-threaded code unless in a dedicated worker context.