-
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
Composer: add clear command that bypasses the event count #46091
Composer: add clear command that bypasses the event count #46091
Conversation
…ount"" This reverts commit c1ceada.
Only got one last bug, where there is a race condition where the input gets cleared but after some time the previous input suddenly returns. I know the cause for this and just have to think for a solid fix. Should be ready by tmrw! |
On web when I type and select an emoji from the popup menu it appears the emoji is not sent, only the partially typed emoji code (this only seems to happen when the partially typed code is 2 characters long): Screen.Recording.2024-07-26.at.16.07.14.mov |
good catch, thanks, taking a look! |
I had some weird code on web where I was taking the previous text value for sending (no clue why I added that). Its now taking the current value of text input which works reliable 👍 Mind checking again @Ollyws ? |
I'm still able to reproduce this intermittently on Desktop while pressing the send button (not reproducible on web as the send button isn't working): Skip to the end to see the actual issue reproduced. Screen.Recording.2024-07-28.at.14.14.27.mov |
@Ollyws thanks for testing so rigorously! This should be fixed now! Screen.Recording.2024-07-29.at.08.58.38.mov |
Reviewer Checklist
Screenshots/VideosAndroid: Native01_Android_Native.mp4Android: mWeb Chrome02_Android_Chrome.mp4iOS: Native03_iOS_Native.mp4iOS: mWeb Safari04_iOS_Safari.mp4MacOS: Chrome / Safari05_MacOS_Chrome.mp4MacOS: Desktop06_MacOS_Desktop.mp4 |
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.
src/pages/home/report/ReportActionCompose/ReportActionCompose.tsx
Outdated
Show resolved
Hide resolved
✋ 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/puneetlath in version: 9.0.15-0 🚀
|
🚀 Deployed to production by https://github.com/roryabraham in version: 9.0.15-9 🚀
|
FYI @hannojg this got reverted. |
Details
This PR fixes an issue where the composer's text input wouldn't show the value the user expects (ie. it wouldn't immediately clear). The following use case now works:
Its the second attempt after this PR:
which got reverted due to:
(I added the reproduction of this bug as test case)
Solution explained
This PR fixes the problem by adding an explicit
clear
view command to the native text input view managers for clearing the text input.Usually when calling
testInputRef.clear()
or setting the value prop to""
it internally calls a view command calledsetTextAndSelection("", 0, 0)
.setTextAndSelection
is using an event count mechanism. It drops events from JS that have an outdated event count.The problem is that when we type text, click send, it can happen the user types more text before the
setTextAndSelection("", 0, 0)
event reached the native side. Once it arrives it is already outdated and is simply dropped.Our explicit
clear
view command always takes the latest event count on the native side (and actually also increments it, so any further updates that might happened in between get dropped).I recommend watching this recording with the solution in place. You can see how the JS thread is lacking behind as we rapidly send new messages:
ios-native.mov
The clearing now is guaranteed to happen immediately after pressing the enabled send button.
For sending, we don't rely on the
value
state which could be outdated when the JS thread catches up and is ready to process sending, but on thetext
parameter we receive in newly addedonClear
callback.This mechanism ensures that the full typed message gets send.
Code changes explained
shouldClear: boolean
prop. Now the composer is just cleared using a ref method (this greatly simplified the clearing flow)<TextInput />
now has an explicit view command calledclear()
<TextInput />
now accepts aonClear
prop.text
parameter, which is the value of the text that was cleared.clear()
onClear
callback we take the text and send the message with that textprepareCommentAndResetComposer
method. Before we would imperatively call this method to signal we want to clear the composer. Now, we just call the view commandclear
and wait for theonClear
callback to get us the comment value we need to send.Upstream PR at facebook/react-native
I discussed this with multiple people and figured the best way is to first start a discussion on the react-native repo. I suspect that such a change can take a long while until it gets merged to react-native in some way:
It might also be that meta doesn't want to do any of these changes. In this case we already discussed on slack that we might want to look into writing our own expensify text input component that extends react-native's.
There exists an issue for that in react-native:
Fixed Issues
$ #37896
PROPOSAL:
Tests
Note: For web there is a bug on
main
that prevents pressing the send button. Make sure to setUSE_REACT_STRICT_MODE: false
in theCONFIG.ts
12121212
fast34343434
56565656
Note: This changed code around the composer. Please test every composer action you can think of (including emojis, mentions, markdown, etc.)
Offline tests
n/a
QA Steps
Same as testing
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-native.mov
Android: mWeb Chrome
mWeb-android.mov
iOS: Native
ios-native.mov
iOS: mWeb Safari
mWeb-ios.mov
MacOS: Chrome / Safari
web.mov
MacOS: Desktop
desktop.mov