Replies: 1 comment
-
|
This is a phenomenal and highly critical question for anyone building deep, low-level JavaScript wrappers or real-time web applications in the Blazor ecosystem. To give you a direct answer based on the architectural direction of the .NET WebAssembly runtime: No, there is currently no plan to offer an official "hybrid" mode where .NET stays on the UI thread while WasmEnableThreads is active. The Deputy Thread model is the intended and supported long-term path forward for multi-threading. Here is the architectural rationale behind this decision, along with the implications for the ecosystem:
To ensure platform safety and prevent unstable web apps, the team designed the Deputy Thread Model. In this model, the UI thread acts purely as a thin proxy for rendering and event forwarding, while the entire runtime lives off-main-thread.
To solve this, developers and library maintainers are moving toward two design patterns: Declarative Interop (Pre-Event Registration): Instead of waiting for .NET to dynamically decide whether to prevent a default behavior, the intention must be registered on the JS side before the event bubbles up (similar to how Blazor uses @OnClick:preventDefault). JS Isolation for UI-Sensitive Loops: Logic that requires tight, synchronous coupling with browser APIs (like Web Audio, precise canvas loops, or input interceptors) must be authored natively in JavaScript/TypeScript on the UI thread, bypassing .NET execution for that specific immediate loop. While community solutions like SpawnDev.BlazorJS.WebWorkers are incredible engineering feats for keeping .NET on the UI thread, they require developers to manually ensure they don't deadlock their application—a risk that the official framework cannot safely introduce to the broader developer audience. |
Beta Was this translation helpful? Give feedback.
Uh oh!
There was an error while loading. Please reload this page.
-
Question for the panel:
When
WasmEnableThreadsis enabled, .NET moves entirely to a background Web Worker, making synchronous JS-to-.NET calls (DotNet.invokeMethod) impossible. This breaks libraries that provide 1-to-1 JavaScript API wrappers — including SpawnDev.BlazorJS (147,000+ downloads) — because the JavaScript spec requires synchronous handling for operations likeevent.preventDefault()andbeforeunload.Community-built solutions like SpawnDev.BlazorJS.WebWorkers (90,000+ downloads) already provide multi-threading while keeping the main .NET instance on the UI thread, preserving synchronous interop.
The question: Is there a plan to offer a hybrid mode — threading enabled but .NET stays on the main thread — or is the Deputy Thread the only supported path forward? And is running .NET on the browser's main thread a long-term supported execution model?
Related issue: #54365
Beta Was this translation helpful? Give feedback.
All reactions