Menu

1 / 2

Blazor WASM's Deputy Thread Model Will Break JavaScript Interop - Here's Why That Matters

DEV Community·Todd Tanner·6 months ago
#IdWixd6W
#blazor#webassembly#dotnet#javascript#thread
Reading 0:00
15s threshold

The Problem

Microsoft is changing how .NET runs inside WebAssembly. When you enable threading with <WasmEnableThreads>true</WasmEnableThreads> , the entire .NET runtime moves off the browser's main thread and onto a background Web Worker — what they call the "Deputy Thread" model .

This sounds like a good idea on paper. The UI stays responsive. .NET gets real threads. Everyone wins.

Except it breaks JavaScript interop. Not in a subtle, edge-case way. It breaks it fundamentally .

What Actually Happens

In traditional Blazor WASM (no threading), .NET and JavaScript share the same thread. When JavaScript calls DotNet.invokeMethod , the CPU jumps from the JS stack to the C# stack and back. It's fast. It's synchronous. It works.

In the Deputy Thread model, .NET lives in a Web Worker. JavaScript lives on the UI thread. They're in different worlds. When JavaScript tries to call DotNet.invokeMethod , the UI thread would have to block while waiting for the worker to respond.

Browsers don't allow that.…

Continue reading — create a free account

Join HashtagPLUS to read full articles, follow hashtags, vote, and join the conversation.