-
Notifications
You must be signed in to change notification settings - Fork 68
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
Add forwardRef2/memo2 which fixes jsification of Dart props #275
Conversation
… later if we need to
|
||
static String _getJsFunctionName(Function object) => |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Use whitespace-agnostic diff for this section
@@ -551,24 +551,6 @@ main() { | |||
expect(propTypeCheck, isA<JsBackedMap>()); | |||
}); | |||
}); | |||
|
|||
group('props are received correctly without interop interfering with the values:', () { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
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.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@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', () { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
🥳
@aaronlademann-wf @smaifullerton-wk All feedback has been addressed! (including adding a test case for wrapping |
@@ -58,64 +111,62 @@ main() { | |||
reason: 'test setup sanity check'); | |||
} | |||
|
|||
group('memo', () { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Best reviewed with whitespace-agnostic diff; this actually didn't change, but was just moved into a function
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
+1
…rdRef2 and test all ref types
# Conflicts: # lib/hooks.dart # test/hooks_test.dart
@@ -642,97 +643,97 @@ main() { | |||
}); | |||
|
|||
group('useImperativeHandle -', () { | |||
var mountNode = new DivElement(); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
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.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
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.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This fixes failures we were seeing in the Dart dev builds due to the dartfmt being different
QA+1 for every step except:
|
@@ -12,7 +12,10 @@ cache: | |||
|
|||
before_script: | |||
- dartanalyzer . | |||
- dartfmt --line-length=120 --dry-run --set-exit-if-changed . | |||
- | | |||
if [ "$TRAVIS_DART_VERSION" != "dev" ]; then |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
QA +1
|
Motivation
Dart
forwardRef
components 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
forwardRef2
andmemo2
, 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
forwardRef2
This 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
chainRef
works 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
forwardRef
QA Instructions
uiForwardRef
andmemo
: CPLAT-11977 Consume/update typing for forwardRef2/memo2 functions over_react#620