Skip to content

Fix CLI metadata startup loading in WebContainers#3029

Open
culpen90 wants to merge 2 commits into
AssemblyScript:mainfrom
culpen90:fix/webcontainer-version-startup
Open

Fix CLI metadata startup loading in WebContainers#3029
culpen90 wants to merge 2 commits into
AssemblyScript:mainfrom
culpen90:fix/webcontainer-version-startup

Conversation

@culpen90

@culpen90 culpen90 commented Jun 13, 2026

Copy link
Copy Markdown

Fixes #3027.

Summary

  • defer compiler and Binaryen initialization until after metadata-only CLI exits
  • avoid a static Binaryen import in the built asc bundle
  • install an instantiateStreaming fallback while loading compiler startup dependencies, so environments with broken streaming support can still compile
  • add browser test coverage for the version path, bundle shape, and first compile with broken instantiateStreaming

Validation

  • corepack npm run build
  • corepack npm run lint
  • corepack npm run test:browser
  • corepack npm run test:cli
  • corepack npm run test:transform:esm
  • corepack npm run test:transform:cjs

@culpen90 culpen90 marked this pull request as ready for review June 13, 2026 20:52
@CountBleck

Copy link
Copy Markdown
Member

Wouldn't the underlying problem still be present when you try to compile something?

Also, from my testing, I think the issue is that StackBlitz doesn't properly support WebAssembly.instantiateStreaming(), at least in the form WebAssembly.instantiateStreaming(fetch("data:application/wasm;base64,...")).

@culpen90

culpen90 commented Jun 13, 2026

Copy link
Copy Markdown
Author

@CountBleck The first version only avoided loading the compiler/Binaryen for metadata-only exits, so yes, an actual compile could still hit the same broken startup wasm path.

I pushed a follow-up in 0ab3f456 that covers the compile path too. The CLI now installs a temporary WebAssembly.instantiateStreaming fallback while loading the compiler startup dependencies and Binaryen: it still tries native streaming first, but if that fails it falls back to WebAssembly.instantiate(await response.arrayBuffer(), imports).

I also added browser regression coverage that patches WebAssembly.instantiateStreaming to throw and verifies asc.compileString(...) still succeeds, in addition to the existing asc --version check.

@MaxGraey

MaxGraey commented Jun 14, 2026

Copy link
Copy Markdown
Member

install an instantiateStreaming fallback while loading compiler startup dependencies, so environments with broken streaming support can still compile

Hmm, I'm not sure we should provide compile streaming fallback from our side. importWithInstantiateStreamingFallback add extra async abstructions for compile streaming for most of browsers which support streaming.

It's much better to have the environment load the polyfill if it really required this by itself. For example use this one: https://www.npmjs.com/package/wasm-instantiate-streaming

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

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

TypeError: WebAssembly.compile expects a Response object in WebContainer environments

3 participants