Callback refs with non-dynamic arguments weren't being handled properly, and would result in obtuse error messages.
Example:
dynamic ref argument (works):
Foo({'ref': (ref) => _fooRef = ref})
non-dynamic ref argument (does not work):
Foo({'ref': (FooComponent ref) => _fooRef = ref})
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.
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.
This is because allowInterop was not called on the provided function.
Solution
Null
arity hack shown here: https://github.com/dart-lang/language/issues/3758Testing
is _CallbackRef<Null>
check tois _CallbackRef<dynamic>
as dynamic
cast in the ref invocation