js-interop: Breaking issue with all JS classes named 'Node' #26532
Labels
closed-duplicate
Closed in favor of an existing report
web-js-interop
Issues that impact all js interop
We have come across a gnarly issue in the Dart interop with JavaScript. In short, it doesn't seem possible to wrap any JS class named
Node
, even if it has been declared with an@JS()
interface and isolated in a dedicated namespace, due to a conflict with dart:html's Node.Recipe to reproduce
We have been able to reproduce the issue with a reduced example:
After loading both the above, we can run the following code:
Details
The error is manifesting for us when trying to use ProseMirror from Dart, specifically uses of its Node class (I can provide an internal code reference if you ping me at sebcevey@). Note that all other wrapped classes (e.g.
Schema
,ProseMirror
, etc) behave as expected; onlyNode
is failing.When running off the Dart code in Dartium, the code executes but we get the following warning on the console:
When running off a compiled JS bundle, the code fails with the following error:
We have been able to track down the issue to the interceptor resolution logic, which incorrectly identifies ProseMirror's Node class with the dart:html Node class. This is because the interceptor lookups fall back to the
typeNameInChrome
function which returns thefn.constructor.name
string (in this case 'Node'), which then gets matched up with Dart's interface for dart:html Node. We can see that erroneous interceptor on the record patched onto the ProseMirror Node prototype.In contrast, other wrapped classes which do work as expected don't match any known names and receive
UnknownJavaScriptObject_methods
as interceptor. Note that we weren't sure whether this is the expected code path?Can you please advise whether this is a known issue, and if there is any workaround we can use?
The text was updated successfully, but these errors were encountered: