Workiva / react-dart

Dart Bindings for React JS
BSD 2-Clause "Simplified" License
413 stars 67 forks source link

Fix callback refs with non-dynamic args failing in Dart 2 #197

Closed greglittlefield-wf closed 5 years ago

greglittlefield-wf commented 5 years ago

Motivation

Callback refs with non-dynamic arguments weren't being handled properly, and would result in obtuse error messages.

Example:

In DDC, the ref function would be called correctly, but the ref argument would be of type NativeJavaScriptObject instead of the expected component class. This is because the JS component was being passed instead of the Dart one.

In dart2js, React would throw upon creation of the ReactElement, with the following error.

Invariant Violation: addComponentAsRefTo(...): Only a ReactOwner can have refs. You might be adding a ref to a component that was not created inside a component's render method, or you have multiple copies of React loaded (details: https://fb.me/react-refs-must-have-owner).

This is because allowInterop was not called on the provided function.

Solution

Testing

aaronstgeorge-wf commented 5 years ago

Nice nice nice nice

smaifullerton-wk commented 5 years ago

QA +1

smaifullerton-wk commented 5 years ago

+10 - typo fixes do not impact QA