-
Notifications
You must be signed in to change notification settings - Fork 2.9k
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
[TS migration] Improve ref types #40698
[TS migration] Improve ref types #40698
Conversation
CLA Assistant Lite bot All contributors have signed the CLA ✍️ ✅ |
@marcochavezf Please copy/paste the Reviewer Checklist from here into a new comment on this PR and complete it. If you have the K2 extension, you can simply click: [this button] |
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.
Great work! I've left some feedback, you missed some files that we should refactor. DMed with more examples on slack 🚀
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.
Did just an early review since the PR is not ready yet, but some points:
1) About this:
Bug caused by usage of refs was found and fixed. The AutocompleteSuggestions component was handling long press events by overriding onpointerdown handler. But the reference to dom element wasn't ready during useEffect hook and result was that the autocomplete was closing on mobile browsers when suggestion was pressed for longer time. It was fixed by using onPointerDown provided by react-native-web.
Is it something that you discovered while working on this issue? If not, could you please link the GH issue related to the bug and add to the PR description?
2) I agree with your reasonings, but I think we should make this more explicit e.g adding some instructions to TS_STYLE.md
. WDYT? cc @blazejkustra
3) Please follow these instructions here to sign the CLA.
4) I've noticed your commits are unsigned, all commits in the repo must be GPG-signed.
395c485
to
6938014
Compare
I have read the CLA Document and I hereby sign the CLA |
Hey! I see that you made changes to our Form component. Make sure to update the docs in FORMS.md accordingly. Cheers! |
@fabioh8010 @blazejkustra thanks for your review! |
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.
Last nit and we're good to open to review @jnowakow !
Co-authored-by: Fábio Henriques <fabio.lacerda@outlook.com>
Reviewer Checklist
Screenshots/VideosMacOS: Chrome / SafariScreen.Recording.2024-04-29.at.01.43.58.movScreen.Recording.2024-04-29.at.01.38.41.mov |
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.
LGTM
Conflicts |
@jnowakow friendly bump to resolve conflicts :) |
@marcochavezf, sorry, I was out of office last week. I've resolved conflicts |
✋ 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 production by https://github.com/marcaaron in version: 1.4.71-6 🚀
|
Details
This PR is a follow up of the TS migration. It's aim was to figure out way of handling refs in the project as in many places the types were defined as union of React Native's components and HTML elements.
Bug caused by usage of refs was found and fixed. The
AutocompleteSuggestions
component was handling long press events by overridingonpointerdown
handler. But the reference to dom element wasn't ready duringuseEffect
hook and result was that the autocomplete was closing on mobile browsers when suggestion was pressed for longer time. It was fixed by usingonPointerDown
provided by react-native-web.In general we should avoid using DOM elements as ref types. That's React Native Web handles references on web so there's no need to explicitly use types like
HTMLDivElement
. Exception of this rule is when we explicitly need to use functions available only in DOM and not in React Native, e.g.getBoundingClientRect
. It's heavily used inTooltip
andPopover
which are only used on web.When adding handlers for Pointers and Mouse events the interaction API provided by React Native Web is preferred option. It's generally satisfied across the app.
In general if there is no need to use DOM specific methods then one should use View as ref type. This PR updates types in several places to follow this pattern. Union types like
View | HTMLDivElement
should be used only in places where DOM api is necessary. Technically components on web have type equal toView & HTMLDivElement
because they have methods available on both platforms. But it's not true in case of native components and this is why union should be used. It enforces developer to explicitly check if metod on property exist on the reference object. While it may be a bit cumbersome it prevents runtime bugs.Unfortunately, union types forces us to use type casting. This is because
HTMLDivElement
can't be passed toView
. It should be done as soon as possible to prevent such types to be propagated. There are utility functions likeviewRef
defined to achieve that.Fixed Issues
$ #39116
PROPOSAL: N/A
Tests
Offline tests
N/A
QA Steps
Same as described in Tests
PR Author Checklist
### Fixed Issues
section aboveTests
sectionOffline steps
sectionQA steps
sectiontoggleReport
and notonIconClick
)myBool && <MyComponent />
.src/languages/*
files and using the translation methodSTYLE.md
) were followedAvatar
, I verified the components usingAvatar
are working as expected)StyleUtils.getBackgroundAndBorderStyle(theme.componentBG)
)Avatar
is modified, I verified thatAvatar
is working as expected in all cases)Design
label and/or tagged@Expensify/design
so the design team can review the changes.ScrollView
component to make it scrollable when more elements are added to the page.main
branch was merged into this PR after a review, I tested again and verified the outcome was still expected according to theTest
steps.Screenshots/Videos
Android: Native
android_after.mov
Android: mWeb Chrome
before:
android_web_before.mov
after:
android_web_after.mov
iOS: Native
ios_after.mov
iOS: mWeb Safari
ios_web_after.mov
MacOS: Chrome / Safari
web_after.mov
MacOS: Desktop
desktop_after.mov