Add forwardRef2/memo2 which fixes jsification of Dart props#275
Add forwardRef2/memo2 which fixes jsification of Dart props#275aaronlademann-wf merged 37 commits intomasterfrom
Conversation
… later if we need to
| JsFunctionComponent get type => reactFunction; | ||
| } | ||
|
|
||
| static String _getJsFunctionName(Function object) => |
There was a problem hiding this comment.
Use whitespace-agnostic diff for this section
| }); | ||
| }); | ||
|
|
||
| group('props are received correctly without interop interfering with the values:', () { |
There was a problem hiding this comment.
These were moved to the common factory tests so they run for all Dart components and Dart component HOCs, not just Dart function components
72088b7 to
4a0cbfb
Compare
This reverts commit 3dacc70.
aaronlademann-wf
left a comment
There was a problem hiding this comment.
@greglittlefield-wf this is awesome work!
Found a couple of small things.
Also, do we have a test for the case where a memo2 wraps a forwardRef2? I know we loosened the typing on memo2 to allow for it - but I don't think I saw a test asserting that it works. Would be nice to have to prevent future regressions.
| }); | ||
|
|
||
| group('when refs come from sources where they have been potentially converted:', () { | ||
| test('ReactElement.ref', () { |
|
@aaronlademann-wf @smaifullerton-wk All feedback has been addressed! (including adding a test case for wrapping |
| reason: 'test setup sanity check'); | ||
| } | ||
|
|
||
| group('memo', () { |
There was a problem hiding this comment.
Best reviewed with whitespace-agnostic diff; this actually didn't change, but was just moved into a function
…rdRef2 and test all ref types
# Conflicts: # lib/hooks.dart # test/hooks_test.dart
| }); | ||
|
|
||
| group('useImperativeHandle -', () { | ||
| var mountNode = new DivElement(); |
There was a problem hiding this comment.
Best viewed with whitespace-agnostic diff; besides changing to forwardRef2, these were just indented
| if (ref is ReactComponent) return ref.dartComponent ?? ref; | ||
|
|
||
| return (ref as ReactComponent).dartComponent ?? ref; | ||
| return ref; |
There was a problem hiding this comment.
These changes were to fix an error when setting a string ref on a component using useImperativeHandle (because it would try to cast the customized ref to ReactComponent).
This an edge-case, but it was easier to fix the issue than to skip testing that case.
|
QAing now... I think this just needs to be formatted? |
| - dartfmt --line-length=120 --dry-run --set-exit-if-changed . | ||
| - | | ||
| if [ "$TRAVIS_DART_VERSION" != "dev" ]; then | ||
| dartfmt --line-length=120 --dry-run --set-exit-if-changed . |
There was a problem hiding this comment.
This fixes failures we were seeing in the Dart dev builds due to the dartfmt being different
QA+1 for every step except:
|
| - dartanalyzer . | ||
| - dartfmt --line-length=120 --dry-run --set-exit-if-changed . | ||
| - | | ||
| if [ "$TRAVIS_DART_VERSION" != "dev" ]; then |
|
QA +1
|

Motivation
Dart
forwardRefcomponents andmemo-wrapped components were being passed JSified props due to the use of JS component factories, when they expected to be getting non-converted Dart props.Solution
tl;dr: I added
forwardRef2/memo2, added a bunch of tests around refs, and fixed a bunch of issues surfaced by test failures.Add
forwardRef2andmemo2, which return Dart component factories so they don't convert propsI had to make new versions because fixing the issues required return type changes that would be breaking. We can consume these new versions under the hood in over_react's memo/uiForwardRef without any breakages.
Remove prop de-converting logic from
forwardRef2This was only a partial solution to wrapping JS components, only applying to callbacks
Also, now that we're using Dart component factories, this logic would prevent Dart event handlers from being converted.
So, since we'll need a more holistic solution to the problem of wrapping JS components, and it wouldn't be easy to retain this logic without breaking other behavior, it was removed.
Update common factory tests:
These verify that the main issue that motivated this PR (converted JS props being passed to Dart components) is fixed
chainRefworks with refs that come from forwardRef2 callback args (as well as ReactElement, since it experienced a similar problem)Update event handler tests to not test de-conversion of props via
forwardRefQA Instructions
uiForwardRefandmemo: CPLAT-11977 Consume/update typing for forwardRef2/memo2 functions over_react#620