-
Notifications
You must be signed in to change notification settings - Fork 10.5k
Description
Is there an existing issue for this?
- I have searched the existing issues
Describe the bug
This is a bit of a strange and niche issue.
When using JSImport/JSExport for WASM Blazor, the identity of returned JSObject's are synchronized between the .NET (WASM) engine and the JavaScript engine. Meaning the same .NET JSObject is returned for the same JavaScript object. (Unless it has already been disposed or garbage collected).
This is a really nice feature, because it allows you to synchronize various things between the two worlds.
But this doesn't seem to work when the JavaScript object is a constructor, for example:
export function getDivElement() {
return HTMLDivElement;
}
This means that code like:
element.constructor == HTMLDivElement
Doesn't work inside the .NET engine, because the JSObject from HTMLDivElement doesn't maintain it's instance correctly.
It's a bit hard to explain, so please see the attached BlazorJSImportBugReport.zip
BlazorJSImportBugReport.zip
Clicking "Test Regular Objects" shows that the JSObject instances works correctly with regular objects:

Clicking "Test HTMLDivElement Constructor" shows that it doesn't work for constructor objects:

Expected Behavior
I would expact any JavaScript object returned by a JSImport function to maintain it's identity, so the same JSObject is returned for the same JavaScript object. (Unless the JSObject has been disposed or garbage collected)
Steps To Reproduce
Use the attached demo project (See Home.razor, CallJavaScript1.cs and test.js)
Exceptions (if any)
No response
.NET Version
10.0.100 (But the problem is also in .NET 9 and probably also 8)
Anything else?
No response