Skip to content

js-interop: Breaking issue with all JS classes named 'Node' #26532

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Closed
theefer opened this issue May 25, 2016 · 4 comments
Closed

js-interop: Breaking issue with all JS classes named 'Node' #26532

theefer opened this issue May 25, 2016 · 4 comments
Labels
closed-duplicate Closed in favor of an existing report web-js-interop Issues that impact all js interop

Comments

@theefer
Copy link

theefer commented May 25, 2016

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:

final a = getFooBar();
print(a.test1());
// prints 'FooBar.test1'

final b = getNode();
print(b.test2());
// throws "NoSuchMethodError: method not found: 'test2$0' (J.getInterceptor$x(...).test2$0 is not a function)"

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; only Node is failing.

When running off the Dart code in Dartium, the code executes but we get the following warning on the console:

Return value for method: node is Node which is inconsistent with all typed JS interop definitions for method node.

When running off a compiled JS bundle, the code fails with the following error:

NoSuchMethodError: method not found: 'get$content' (J.getInterceptor$x(...).get$content is not a function)

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 the fn.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?

@DisDis
Copy link

DisDis commented May 25, 2016

duplicate #25785

@kevmoo
Copy link
Member

kevmoo commented May 25, 2016

@jacob314 can you confirm this is a dupe of #25785 ?

@kevmoo kevmoo added the web-js-interop Issues that impact all js interop label May 25, 2016
@DisDis
Copy link

DisDis commented May 25, 2016

@kevmoo identical stack trace:
main.dart.js:5530 Uncaught TypeError: J.getInterceptor$x(...).setItems$2 is not a function

@theefer
Copy link
Author

theefer commented May 25, 2016

If the tag is the same as a reserved name, it does not return the correct Interceptor.

I do think it is a dupe of #25785. Feel free to close this issue if you'd rather only keep one canonical bug open, I will track that one instead.

It's a really problematic issue because no workaround has been put forward. The only hack I can think of is to either fork the original JavaScript codebase, or to monkey patch and rename every reference to the offending symbol before it is loaded.

In the case of ProseMirror, because it has its own model of the DOM as classes of similar names, I think I would have to hack the name of a number of different classes (Node, Text, etc).

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
closed-duplicate Closed in favor of an existing report web-js-interop Issues that impact all js interop
Projects
None yet
Development

No branches or pull requests

3 participants