Repository navigation
Description
Current behavior 🐛
Two public APIs on Uno.Foundation.WebAssemblyRuntime call JavaScript globals that no WebAssembly app built on the Skia renderer loads:
| API | JavaScript it needs | What happens |
|---|---|---|
InvokeAsync(string) / InvokeAsync(string, CancellationToken) |
Uno.UI.Interop.AsyncInteropHelper.Invoke |
The generated script (Runtime.wasm.cs:284-295) throws TypeError: Cannot read properties of undefined (reading 'Invoke') inside InvokeJS, so the returned Task faults. |
InvokeJSUnmarshalled(string, IntPtr) / InvokeJSUnmarshalled(string, IntPtr, IntPtr) |
MonoSupport.jsCallDispatcher.invokeJSUnmarshalled |
The [JSImport] in WebAssembly.Runtime.cs:21 targets a function that does not exist. GetMethodId calls it outside any try, so the call throws. |
Those globals were defined only in src/Uno.UI/ts (Interop/AsyncInteropHelper.ts, MonoSupport.ts, WindowManager.ts). The only project that compiled that TypeScript was the native WebAssembly DOM head, Uno.UI.Wasm.csproj:
- 6.x: at
6.7.103, the Skia WebAssembly Browser runtime'stsconfig.jsonpulled in only../Uno.UI/ts/types/**andWebView.tsfrom that folder.Uno.UI.Wasm.csprojis the only project that compiled the rest. By that inspection, these APIs worked on the native DOM renderer but never on the Skia renderer. - 7.0: commit c3608f4 removed the native WebAssembly DOM project heads. Since then nothing compiles
src/Uno.UI/ts, so both APIs are broken for every WebAssembly app. docs: Close out the 7.0 documentation and reconciliation leftovers #24351 deletes the orphaned sources; the implementations remain in history at6.7.103.
The 7.0 migration guide doesn't mention either API. Its legacy JS interop entry says only that InvokeJS(string) is kept as a legacy API, so both read as supported.
Expected behavior 🎯
Either:
- both APIs work on the Skia WebAssembly renderer, or
- they are removed (or marked obsolete) as a documented 7.0 breaking change, pointing to
[JSImport]/[JSExport], as the guide already does for the rest of the legacy JS interop.
How to reproduce it (as minimally and precisely as possible) 🔬
Verified at runtime. I opened the Skia WebAssembly SamplesApp staging builds and evaluated in the browser console:
- fix: Refresh NavigationView ancestor selection #24509: based on
master, without docs: Close out the 7.0 documentation and reconciliation leftovers #24351 - docs: Close out the 7.0 documentation and reconciliation leftovers #24351
typeof Uno.UI.Interop.AsyncInteropHelper // "undefined"
typeof Uno.UI.WindowManager // "undefined"
typeof MonoSupport // ReferenceError: MonoSupport is not defined
Object.keys(Uno.UI.Interop) // ["Runtime"]
// The exact script InvokeAsync generates, run through the same entry point InvokeJS uses:
Uno.UI.Interop.Runtime.InvokeJS("const __f = ()=>Promise.resolve('x');\nUno.UI.Interop.AsyncInteropHelper.Invoke(1, __f);")
// TypeError: Cannot read properties of undefined (reading 'Invoke')Both builds give identical results.
Expected managed-side behavior (from the code; this C# was not run). In a Skia WebAssembly app:
// Faults: the JS TypeError surfaces from InvokeJS and InvokeAsync returns Task.FromException.
var result = await Uno.Foundation.WebAssemblyRuntime.InvokeAsync("Promise.resolve('ok')");Workaround 🛠️
Use [JSImport]/[JSExport] from System.Runtime.InteropServices.JavaScript directly. For a promise, a [JSImport] method returning Task<string> does the same job as InvokeAsync.
Renderer 🎨
- Skia
- Native
Affected platforms 📱💻🖥️
WebAssembly
Uno.Sdk version (and other relevant versions) 📦
- 7.0 development builds (
mastersince c3608f4): broken for all WebAssembly apps. Verified at runtime. - 6.x on the Skia renderer: broken by inspection of
6.7.103. Not verified at runtime.
IDE version 🧑💻
N/A
Anything else we need to know? 💬
Options
- Restore: reimplement
AsyncInteropHelper.Invokeinsrc/Uno.UI.Runtime.Skia.WebAssembly.Browser/ts/Runtime/, and the unmarshalled dispatcher too if it is kept. Ideally don't reintroduceeval:InvokeAsyncbuilds and evaluates a script string today, which is the pattern [WebAssembly] Uno.UI requires'unsafe-eval'in the page's Content Security Policy #24429 wants to remove. - Remove for 7.0: drop
InvokeAsyncandInvokeJSUnmarshalledfromWebAssemblyRuntime. That means amigrating-to-uno-7.mdentry next to the existing legacy JS interop entry, plusPackageDiffIgnore.xmlentries. Downstream Uno libraries may still call them, so check before choosing.
Dead code found while tracing this (safe to remove with either option):
src/Uno.WinRT/UI/Core/CoreWindow.Interop.wasm.cs: aSetCursor[JSImport]targetingglobalThis.Uno.UI.WindowManager.current.setCursor. It has no callers; the Skia WebAssembly cursor goes throughBrowserPointerInputSource's own import.TSInteropMarshaller: no callers outsidesrc/Uno.Foundation.Runtime.WebAssembly/Interop/. Not yet verified: whetherTSBindingsGeneratorand thetsBindings/**entries in theUno.WinRTand Browser runtimetsconfig.jsonfiles are dead as well.doc/articles/uno-development/uno-internals-wasm.mdstill says C# calls into JavaScript through theWindowManagerTypeScript class.
Related: #24429 ('unsafe-eval' CSP requirement of the eval-based interop).
Activity
refactor(wasm)!: Remove interop whose JavaScript is no longer shipped
refactor(wasm)!: Remove interop whose JavaScript is no longer shipped
refactor(wasm)!: Remove interop whose JavaScript is no longer shipped
refactor(wasm)!: Remove interop whose JavaScript is no longer shipped
refactor(wasm)!: Remove interop whose JavaScript is no longer shipped