Skip to content

Commit 20be0a3

Browse files
committed
Improve instantiateStreaming fallback
This commit improves our `instantiateStreaming` fallback to only actually trigger the fallback if the headers look wrong. If the headers look right then we let through the original error which should help avoid accidentally papering over bugs with different bugs in misconfigured situations. Closes rustwasm#1696
1 parent 906ac15 commit 20be0a3

File tree

1 file changed

+12
-6
lines changed
  • crates/cli-support/src/js

1 file changed

+12
-6
lines changed

crates/cli-support/src/js/mod.rs

+12-6
Original file line numberDiff line numberDiff line change
@@ -536,13 +536,19 @@ impl<'a> Context<'a> {
536536
if (typeof WebAssembly.instantiateStreaming === 'function') {{
537537
result = WebAssembly.instantiateStreaming(response, imports)
538538
.catch(e => {{
539-
console.warn(\"`WebAssembly.instantiateStreaming` failed. Assuming this is \
540-
because your server does not serve wasm with \
541-
`application/wasm` MIME type. Falling back to \
542-
`WebAssembly.instantiate` which is slower. Original \
543-
error:\\n\", e);
544539
return response
545-
.then(r => r.arrayBuffer())
540+
.then(r => {{
541+
if (r.headers.get('Content-Type') != 'application/wasm') {{
542+
console.warn(\"`WebAssembly.instantiateStreaming` failed \
543+
because your server does not serve wasm with \
544+
`application/wasm` MIME type. Falling back to \
545+
`WebAssembly.instantiate` which is slower. Original \
546+
error:\\n\", e);
547+
return r.arrayBuffer();
548+
}} else {{
549+
throw e;
550+
}}
551+
}})
546552
.then(bytes => WebAssembly.instantiate(bytes, imports));
547553
}});
548554
}} else {{

0 commit comments

Comments
 (0)