Skip to content

Conversation

@SteveSandersonMS
Copy link
Member

Previously we:

  • Attempted to compile using instantiateStreaming
  • ... and if that failed, attempted to compile using instantiate

The problem is that this kind of fallback has never worked, because the first call to instantiateStreaming consumes the response body, so the second step would be guaranteed to fail in all cases.

We could solve this using response.clone(), but there's no known use case for the fallback anyway. As long as we only attempt to use instantiateStreaming when the content-type application/wasm is found (as per spec), then it should work, and if not there's no reason to think that instantiate would be more successful.

So as of this PR, we don't do fallback - we just pick between the two compilation APIs based on the content-type. This should increase our compatibility versus what we did before.

Fixes one of the main concerns raised in #42055

@SteveSandersonMS SteveSandersonMS requested a review from a team as a code owner July 26, 2022 12:47
@ghost ghost added the area-blazor Includes: Blazor, Razor Components label Jul 26, 2022
@SteveSandersonMS SteveSandersonMS added this to the 7.0-rc1 milestone Jul 26, 2022
Comment on lines +667 to 670
if (!hasWasmContentType) {
// In most cases the developer should fix this. It's unusual enough that we don't mind logging a warning each time.
console.warn('WebAssembly resource does not have the expected content type "application/wasm", so falling back to slower ArrayBuffer instantiation.');
}
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

we only attempt to use instantiateStreaming when the content-type application/wasm is found (as per spec), then it should work, and if not there's no reason to think that instantiate would be more successful.

In that case, should we just throw an exception given we don't expect the subsequent array buffer instantiation to work if !hasWasmContentType?

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Non-streaming compilation should work regardless of the content type. It’s only streaming compilation that has the content type prerequisite.

Copy link
Member Author

@SteveSandersonMS SteveSandersonMS Jul 26, 2022

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think the way I phrased the PR description was ambiguous and perhaps misleading. Hopefully the code itself does a better job of explaining!

Copy link
Contributor

@TanayParikh TanayParikh left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks for the clarification! LGTM

@SteveSandersonMS SteveSandersonMS merged commit 19dcc4c into main Jul 29, 2022
@SteveSandersonMS SteveSandersonMS deleted the stevesa/fix-wasm-compilation-fallback branch July 29, 2022 09:19
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

area-blazor Includes: Blazor, Razor Components

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants