-
Notifications
You must be signed in to change notification settings - Fork 3.5k
Fixed correct original props callback on cloneElement #15990
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
Fixed correct original props callback on cloneElement #15990
Conversation
|
cc @iwiznia |
iwiznia
left a comment
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.
Sorry but I am not sure I get it, aren't both codes equivalent? Is the problem that the previous code did not have the correct context attached to the function and thus if those use this, it would break?
|
@iwiznia They are not equivalent, it's not about the context,
The methods are inside |
|
Ohhh 🤦 I missed that 😄 |
|
@iwiznia Thanks for the quick review |
|
@iwiznia Can you please fill the PR reviewer checklist? |
|
I have pushed a commit that fixes the same issue for The bug is the following piece of code will never work as you'd expect <Form>
<TextInput ref={r => this.texInput = r} onBlur={this.callThePolice} />
</Form>
This PR should fix that as well. |
|
@s77rt can you add tests to make sure that each piece of the code you touched is working correctly? |
|
Hey! I see that you made changes to our Form component. Make sure to update the docs in FORMS.md accordingly. Cheers! |
|
@cead22 The changes will mostly prevent future bugs and save debug time more than solve a current bug. I have added a video for Web confirming Hoverable, Tooltip and Form are working correctly. I think that would be enough for this case, LMK if something else is needed. @MelvinBot I'm not modifying anything major on Forms, nothing to be updated here. |
|
@s77rt I agree with Carlos, it would be good to just note it in general in the QA steps for Applause to go over once this is in staging |
|
Oh my bad, somehow I read it "tests" but my mind read it "screenshots/videos" 😅 |
|
Added tests. |
Reviewer Checklist
Screenshots/VideosWebMobile Web - ChromeMobile Web - SafariDesktopiOSAndroid |
|
@s77rt I found a new error in the console when clicking on an IOU badge on the left hand navigation, and then clicking the cancel button. I tried a couple of times in main and I couldn't reproduce that same issue. Can you check if you get the same result? Warning: Failed prop type: Invalid prop `pendingAction` of value `[object Object]` supplied to `OfflineWithFeedback`, expected one of ["add","update","delete"].Warning: Failed prop type: Invalid prop `pendingAction` of value `[object Object]` supplied to `OfflineWithFeedback`, expected one of ["add","update","delete"].
at OfflineWithFeedback (webpack-internal:///./src/components/OfflineWithFeedback.js:101:85)
at withNetwork(OfflineWithFeedback)
at withLocalize(withNetwork(OfflineWithFeedback))
at div
at eval (webpack-internal:///./node_modules/@expensify/react-native-web/dist/exports/View/index.js:52:25)
at TouchableWithoutFeedback (webpack-internal:///./node_modules/@expensify/react-native-web/dist/exports/TouchableWithoutFeedback/index.js:46:28)
at IOUPreview (webpack-internal:///./src/components/ReportActionItem/IOUPreview.js:144:13)
at withOnyx (webpack-internal:///./node_modules/react-native-onyx/dist/web.development.js:2135:73)
at withLocalize(Component)
at div
at eval (webpack-internal:///./node_modules/@expensify/react-native-web/dist/exports/View/index.js:52:25)
at div
at eval (webpack-internal:///./node_modules/@expensify/react-native-web/dist/exports/View/index.js:52:25)
at eval (webpack-internal:///./node_modules/@expensify/react-native-web/dist/exports/ScrollView/ScrollViewBase.js:68:24)
at eval (webpack-internal:///./node_modules/create-react-class/factory.js:897:37)
at ScrollView
at div
at eval (webpack-internal:///./node_modules/@expensify/react-native-web/dist/exports/View/index.js:52:25)
at FullPageNotFoundView (webpack-internal:///./src/components/BlockingViews/FullPageNotFoundView.js:65:13)
at withLocalize(FullPageNotFoundView)
at div
at eval (webpack-internal:///./node_modules/@expensify/react-native-web/dist/exports/View/index.js:52:25)
at KeyboardAvoidingView
at div
at eval (webpack-internal:///./node_modules/@expensify/react-native-web/dist/exports/View/index.js:52:25)
at SafeAreaConsumer
at ScreenWrapper (webpack-internal:///./src/components/ScreenWrapper/index.js:69:86)
at withNetwork(ScreenWrapper)
at withOnyx (webpack-internal:///./node_modules/react-native-onyx/dist/web.development.js:2135:73)
at withKeyboardState(Component)
at withWindowDimensions(withKeyboardState(Component))
at WithNavigation (webpack-internal:///./src/components/withNavigation.js:23:93)
at IOUDetailsModal (webpack-internal:///./src/pages/iou/IOUDetailsModal.js:128:86)
at withOnyx (webpack-internal:///./node_modules/react-native-onyx/dist/web.development.js:2135:73)
at withNetwork(Component)
at withLocalize(withNetwork(Component))
at StaticContainer (webpack-internal:///./node_modules/@react-navigation/core/lib/module/StaticContainer.js:13:16)
at EnsureSingleNavigator (webpack-internal:///./node_modules/@react-navigation/core/lib/module/EnsureSingleNavigator.js:17:5)
at SceneView (webpack-internal:///./node_modules/@react-navigation/core/lib/module/SceneView.js:23:5)
at div
at eval (webpack-internal:///./node_modules/@expensify/react-native-web/dist/exports/View/index.js:52:25)
at div
at eval (webpack-internal:///./node_modules/@expensify/react-native-web/dist/exports/View/index.js:52:25)
at div
at eval (webpack-internal:///./node_modules/@expensify/react-native-web/dist/exports/View/index.js:52:25)
at CardSheet (webpack-internal:///./node_modules/@react-navigation/stack/lib/module/views/Stack/CardSheet.js:19:5)
at div
at eval (webpack-internal:///./node_modules/@expensify/react-native-web/dist/exports/View/index.js:52:25)
at AnimatedComponent (webpack-internal:///./node_modules/@expensify/react-native-web/dist/vendor/react-native/Animated/createAnimatedComponent.js:59:88)
at AnimatedComponentWrapper
at Dummy (webpack-internal:///./node_modules/@react-navigation/stack/lib/module/views/GestureHandler.js:15:5)
at div
at eval (webpack-internal:///./node_modules/@expensify/react-native-web/dist/exports/View/index.js:52:25)
at AnimatedComponent (webpack-internal:///./node_modules/@expensify/react-native-web/dist/vendor/react-native/Animated/createAnimatedComponent.js:59:88)
at AnimatedComponentWrapper
at div
at eval (webpack-internal:///./node_modules/@expensify/react-native-web/dist/exports/View/index.js:52:25)
at Card (webpack-internal:///./node_modules/@react-navigation/stack/lib/module/views/Stack/Card.js:60:5)
at CardContainer (webpack-internal:///./node_modules/@react-navigation/stack/lib/module/views/Stack/CardContainer.js:28:5)
at div
at eval (webpack-internal:///./node_modules/@expensify/react-native-web/dist/exports/View/index.js:52:25)
at NativeScreen (webpack-internal:///./node_modules/react-native-screens/lib/module/index.js:58:1)
at AnimatedComponent (webpack-internal:///./node_modules/@expensify/react-native-web/dist/vendor/react-native/Animated/createAnimatedComponent.js:59:88)
at AnimatedComponentWrapper
|
Am I correct that onBlur, onMouseLeave, etc are standard function names that we can't/shouldn't change? |
cead22
left a comment
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.
After going through the reviewer checklist, I wanted to call out a couple of things
|
|
||
| // Call the original ref, if any | ||
| const {ref} = child; | ||
| if (_.isFunction(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.
I verified all code is DRY (the PR doesn't include any logic written more than once, with the exception of tests)
We do this check in many places, where we check if something is a function and if it is we invoke it. Should we replace these instances with Func.invoke like Func.invoke(ref)?
https://github.com/Expensify/expensify-common/blob/36d6f23/lib/Func.jsx#L13
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 is not necessary a repeated logic. Although Func.invoke makes the block of code in one line, it may be confusing; We will have to call Func.invoke(undefined, [ref]). Notice that the arguments must be in an array which is an easy thing to miss.
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.
I won't block on this, since this duplication is already here, but here's why I don't think I agree, just for context
- Just in this PR, we could replace 3 lines of code with 1, in 5 places, so I don't see why this wouldn't be considered repeated logic
- We'll have to call
Func.invoke(red, [node])in this case, the params being in an array is as easy to miss as any other piece of code, like passingnodetoref(node). Passing arguments to a function in an array is pretty standard in JS when usingFunction.prototype.apply
|
@cead22 Thanks for the review!
I can't reproduce that. Can you repeatedly reproduce it? I don't think it's related to the change here and was mostly a coincidence due to some other factors.
No, the checklist you quoted is referring to the callbacks of those functions, they should have a clear naming of what they do. e.g.:
|
Co-authored-by: Carlos Alvarez <cead22@gmail.com>
cead22
left a comment
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.
I couldn't reproduce the console error anymore!
|
|
||
| // Call the original ref, if any | ||
| const {ref} = child; | ||
| if (_.isFunction(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.
I won't block on this, since this duplication is already here, but here's why I don't think I agree, just for context
- Just in this PR, we could replace 3 lines of code with 1, in 5 places, so I don't see why this wouldn't be considered repeated logic
- We'll have to call
Func.invoke(red, [node])in this case, the params being in an array is as easy to miss as any other piece of code, like passingnodetoref(node). Passing arguments to a function in an array is pretty standard in JS when usingFunction.prototype.apply
|
@iwiznia all yours |
|
✋ This PR was not deployed to staging yet because QA is ongoing. It will be automatically deployed to staging after the next production release. |
|
🚀 Deployed to staging by https://github.com/iwiznia in version: 1.2.91-0 🚀
|
|
🚀 Deployed to production by https://github.com/luacmartins in version: 1.2.91-1 🚀
|

@iwiznia
Details
Quick Fix: Just found out that the original callbacks are not being called correctly.
Fixed Issues
$ #16084
Tests
Offline tests
n/a
QA Steps
PR Author Checklist
### Fixed Issuessection aboveTestssectionOffline stepssectionQA stepssectiontoggleReportand notonIconClick)src/languages/*files and using the translation methodWaiting for Copylabel for a copy review on the original GH to get the correct copy.STYLE.md) were followedAvatar, I verified the components usingAvatarare working as expected)/** comment above it */thisproperly so there are no scoping issues (i.e. foronClick={this.submit}the methodthis.submitshould be bound tothisin the constructor)thisare necessary to be bound (i.e. avoidthis.submit = this.submit.bind(this);ifthis.submitis never passed to a component event handler likeonClick)StyleUtils.getBackgroundAndBorderStyle(themeColors.componentBG)Avataris modified, I verified thatAvataris working as expected in all cases)ScrollViewcomponent to make it scrollable when more elements are added to the page.mainbranch was merged into this PR after a review, I tested again and verified the outcome was still expected according to theTeststeps.Screenshots/Videos
Web
web.mp4
Mobile Web - Chrome
Mobile Web - Safari
Desktop
iOS
Android