Compose box is not cleared after sending a message if the user starts typing just after pressing send - iOS / Android
If you haven’t already, check out our contributing guidelines for onboarding and email [email protected] to request to join our Slack channel!
Action Performed:
- Log in to e.cash in mobile and navigate to a conversation
- Type a message and press send
- Immediately after pressing send start typing another message
Expected Result:
Compose box should be cleared after sending the message
Actual Result:
Previous message is still in compose box if the user starts typing just after pressing send
Workaround:
Waiting a bit after pressing send clears the compose box. But this could be a pain for fast typers.
Platform:
Where is this issue occurring?
Web iOS ✔️ Android ✔️ Desktop App Mobile Web
Version Number: 1.0.79-0
Logs: https://stackoverflow.com/c/expensify/questions/4856
Notes/Photos/Videos:
https://user-images.githubusercontent.com/44479856/126039540-46ce81fa-bf45-4df6-85e2-2d5d6f11577f.mov
Expensify/Expensify Issue URL:
From @aliabbasmalik8 https://expensify.slack.com/archives/C01GTK53T8Q/p1626378713340800 and @joaniew https://expensify.slack.com/archives/C01GTK53T8Q/p1626387085365100
Send message takes some time so last message append with next message. we can clear the compose box after he click on send icon. (@aliabbasmalik8)
i noticed on mobile (iOS) there’s a lag between when i hit ‘send’ and when it actually sends. but i’m the type of typer who will start typing a new message expecting the chat box to clear once the message has been sent. what happens in echat is that the message sends, but if i don’t wait for it to send/clear the msg box and start typing immediately, it keeps the original message, which means i have to either go back and delete it or wait until it sends (who knows how long that takes sometimes. Video attached (wait til the 2nd testing chat) (@joaniew)
IMPORTANT PLEASE READ
Instructions on how to make a proposal for this issue:
- Read the entire comment thread to be sure you are not proposing a solution that was already discussed
- Provide a clear explanation of the problem and why it happens
- Provide a clear explanation of the solution and how to implement it
- Provide proof that the solution will solve the issue on iOS/Android (ideally a video of native platform - not web)
- Provide enough detail so that we can implement your solution and verify that it works.
Proposals without this information will be marked as off-topic. Thanks!
Triggered auto assignment to @robertjchen (Engineering), see https://stackoverflow.com/c/expensify/questions/4319 for more details.
I was able to reproduce this behavior in the iOS emulator. Interestingly enough, it doesn't seem to be an issue on the Web-based client.
After unsuccessfully trying some quick JS changes, I think the potential solution might have to involve low-level, native control of the input field behavior. Opening it up for others to try tackling it, perhaps a more suitable JS solution can be found! 👍
Triggered auto assignment to @bfitzexpensify (External), see https://stackoverflow.com/c/expensify/questions/8582 for more details.
Triggered auto assignment to @marcaaron (Exported), see https://stackoverflow.com/c/expensify/questions/7972 for more details.
the problem seems to be related to state management
I can easily fix this; it seems to be the problem because the input field is not controlled. (state management problem) My Upwork profile: https://www.upwork.com/freelancers/~014e072a4daf3ed991 Thanks
the problem seems to be related to state management
@muratti32 How so?
I can easily fix this; it seems to be the problem because the input field is not controlled. (state management problem)
@sonipranjal We had a controlled input used in the past. The performance was very bad.
If it helps, here's where we clear the comment by calling this method with an empty string
https://github.com/Expensify/App/blob/fa355419244df0f583a54ae9e561fab7a9c647bd/src/pages/home/report/ReportActionCompose.js#L419-L420 https://github.com/Expensify/App/blob/fa355419244df0f583a54ae9e561fab7a9c647bd/src/pages/home/report/ReportActionCompose.js#L303-L311
I'm not certain, but if I had to guess there's some conflict between the logic that is doing
setTextInputShouldClear() (which will trigger this.textInput.clear()) and setNativeProps({text: ''})
Proposal
We can try running the submitting after clearing the textField.
setTextInputShouldClear(shouldClear, fn) {
this.setState({textInputShouldClear: shouldClear}, fn ? fn() : undefined);
}
submitForm(e) {
if (e) {
e.preventDefault();
}
const trimmedComment = this.comment.trim();
// Don't submit empty comments
if (!trimmedComment) {
return;
}
this.updateComment('');
this.setTextInputShouldClear(true, () => {
this.props.onSubmit(trimmedComment);
});
}
We can try running the submitting after clearing the textField.
@mananjadhav Interesting, is there some explanation for why this would help?
we update the submitForm in "src/pages/home/report/ReportActionCompose.js" this.setTextInputShouldClear(true); is use the first line in submitForm
@marcaaron, @bfitzexpensify Whoops! This issue is 2 days overdue. Let's get this updated quick!
I would try to clear input first and then trigger the send message functionality. clearing input is a state update so it should not affect the sending message time. and yes updating the state is the only solution I see here, there can be problem with re-rendering and we can optimise the component to avoid re-render by making some components Pure or by using useMemo if that is not implemented yet.
once it submit the message from state, we just need to clear/empty state again.
@marcaaron, @bfitzexpensify Eep! 4 days overdue now. Issues have feelings too...
Sorry, I still don't think we've got the right proposal yet.
It's been >7 days since posting — reposted under a new job on Upwork with price doubled to $500.
Won't this work?
this.textInput.clear();
Won't this work?
this.textInput.clear();
If you check the code, this exists but the issue comes when you click the button and the text simultaneosuly.