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

A report about Safari's WebAssembly implementation being broken #1860

Closed
ianberdin opened this issue Dec 16, 2021 · 6 comments
Closed

A report about Safari's WebAssembly implementation being broken #1860

ianberdin opened this issue Dec 16, 2021 · 6 comments

Comments

@ianberdin
Copy link

Hi,
I'm on integration esbuild in PlayCode.io.

First of all, thank you very much for the amazing work. Figma and esbuild are incredible.

I came across the fact that in Safari web worker esbuild-wasm does not work. After few runs of build/transform, it throws the an error: Maximum call stack size exceeded.
Sandbox (open using Safari with opened Safari console).

Code:

// test.worker.js
import {
  initialize,
  transform
} from 'https://cdn.jsdelivr.net/npm/esbuild-wasm@0.14.5/esm/browser.min.js'

  ;(async function () {
  await initialize({
    worker: false,
    wasmURL: 'https://cdn.jsdelivr.net/npm/esbuild-wasm@0.14.5/esbuild.wasm'
  })

  const r = await fetch(
    'https://cdn.jsdelivr.net/npm/bootstrap@5.1.3/dist/js/bootstrap.js'
  )
  const lib = await r.text()

  let i = 0
  setInterval(async () => {
    await transform(lib, { loader: 'js' })
    self.postMessage(`Build times ${i++}`)
  }, 1500)
})()
// index.js
const worker = new Worker('/test.worker.js', { type: 'module' })

worker.addEventListener('message', ({ data }) => {
  console.log(data)
})

A bit better stack trace:

Error: Transform failed with 1 error:
error: Maximum call stack size exceeded.
failureErrorWithLog
(anonymous function)
(anonymous function)
handleIncomingPacket
readFromStdout
(anonymous function)
write
syscall/js.valueCall
wasm-stub
.wasm-function[1348] .wasm-function[1331]
.wasm-function[1389] .wasm-function[1386]
.wasm-function[1471] .wasm-function[1486]
.wasm-function[3496] .wasm-function[1007]
<?>.wasm-function[1006]
wasm-stub
_resume
(anonymous function)
(anonymous function)
resumeStdin
onmessage
(anonymous function)
writeToStdin
sendRequest
start
transform2
Promise
transform
(anonymous function)

@brynshanahan
Copy link

Just came across this issue as well. Sandbox https://codesandbox.io/s/github/lukedxvxes/esbuild-in-browser/tree/master/?file=/src/bundler/plugins/unpkg-path-plugin.tsx

@evanw
Copy link
Owner

evanw commented Dec 17, 2021

Maybe Safari's WebAssembly implementation is just buggy? I get really weird crashes for this in Safari when I run this on the main thread (no web worker involved). Doing that runs fine in Chrome and Firefox.

@ianberdin
Copy link
Author

@evanw,
I have great news!
Both bugs (Safari does not know how to create a worker inside a worker yet) are closed in Safari technology preview.

But Safari is not Chrome and it won't be updated for at least a year...

Can we find some kind of intermediate solution, hot to catch the instance falling in order to restart and continue?

@evanw
Copy link
Owner

evanw commented Dec 17, 2021

I agree that the way Apple handles Safari updates is very unfortunate. There’s nothing we can do about that though, although I hope that they one day change their minds.

You could try to catch errors and reinstantiate esbuild’s library (which you should be able to do without esbuild’s help) but I wouldn’t recommend it. Running esbuild in a buggy VM is also likely to hang forever or to silently produce the wrong output.

I can think of the following workarounds:

Realistically I’d probably just put up a banner that says something like “Safari’s WebAssembly implementation is known to be broken. Please use another browser.”

@evanw evanw changed the title Maximum call stack size exceeded in Safari web worker. A report about Safari's WebAssembly implementation being broken Dec 20, 2021
@ianberdin
Copy link
Author

Thank you for the detailed answer and advice!
I agree, there is logic in this.

@softmarshmallow
Copy link

Screen Shot 2022-04-09 at 12 41 13 PM

I don't know if this is related, I have webworker + esbuild-wasm implementation works on chrome, doesn't work on safari (including technology preview build)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

4 participants