Open m-natarajan opened 3 weeks ago
Triggered auto assignment to @jliexpensify (Bug
), see https://stackoverflow.com/c/expensify/questions/14418 for more details. Please add this bug to a GH project, as outlined in the SO.
Edited by proposal-police: This proposal was edited at 2024-11-14 08:30:02 UTC.
When the last message sent in a chat includes an attachment, pressing the ArrowUp key does not open the edit box, preventing the user from editing that message
When a message with an attachment is sent, the selection.start value is set to the length of the text in that message. Because of this, the condition in the code that triggers the edit box doesn’t pass, which is why the edit box isn’t activated. hence this condition will be false: https://github.com/Expensify/App/blob/9d8571bc9e504aabbb75c690a3bca3918ed565bd/src/pages/home/report/ReportActionCompose/ComposerWithSuggestions/ComposerWithSuggestions.tsx#L482
when we send the comment without or without attachment, this onClear, is called. https://github.com/Expensify/App/blob/be4d7f50949d52aa9f2cb9a8ac495ef19473edde/src/pages/home/report/ReportActionCompose/ComposerWithSuggestions/ComposerWithSuggestions.tsx#L700
we can set the selection.start to 0 as :
setSelection({ start: 0, end: 0 });
in this part: https://github.com/Expensify/App/blob/be4d7f50949d52aa9f2cb9a8ac495ef19473edde/src/pages/home/report/ReportActionCompose/ComposerWithSuggestions/ComposerWithSuggestions.tsx#L514-L519
the setSelection(e.nativeEvent.selection)
, won't be executed as the !textInputRef.current?.isFocused()
, will be true in the case of sending attachment.
and just to not re-rerun this setSelection({ start: 0, end: 0 });
on the onClear function twice for a text only message, we can add check if the selection.start !== 0
.
if(selection.start !== 0){
setSelection({ start: 0, end: 0 });
}
or
if(!textInputRef.current?.isFocused()){
setSelection({ start: 0, end: 0 });
}
The setSelection({ start: 0, end: 0 });
is also being called in the Composer component’s clear
function
here:
https://github.com/Expensify/App/blob/e6b416726fbe7171e84f048a8874c1b9254b6a26/src/components/Composer/implementation/index.tsx#L278
clear
function in Composer
component is triggered for all messages, regardless of whether they include attachments or are text-only.
https://github.com/Expensify/App/blob/e6b416726fbe7171e84f048a8874c1b9254b6a26/src/components/Composer/implementation/index.tsx#L278
In clear, setSelection({ start: 0, end: 0 })
is called to reset the selection, but it only updates the local state selection
within the Composer component. Since this reset is only applied to Composer's own internal selection state, it doesn’t affect the selection state in ComposerWithSuggestions.
https://github.com/Expensify/App/blob/04402e9f47a77f10b3c2c47fefe0931fbf62e4d4/src/components/Composer/implementation/index.tsx#L63-L68
In ComposerWithSuggestions, we maintain a separate local selection state using which we decide to open the comment edit box if the selection.start <=0,
https://github.com/Expensify/App/blob/e6b416726fbe7171e84f048a8874c1b9254b6a26/src/components/Composer/implementation/index.tsx#L63
This means the selection reset on clear
in Composer
doesn’t propagate to ComposerWithSuggestions
, which is why we need to explicitly update the selection state of ComposerWithSuggestions in the onClear
:
https://github.com/Expensify/App/blob/be4d7f50949d52aa9f2cb9a8ac495ef19473edde/src/pages/home/report/ReportActionCompose/ComposerWithSuggestions/ComposerWithSuggestions.tsx#L700
Edited by proposal-police: This proposal was edited at 2024-11-12 04:40:00 UTC.
Up to edit feature doesn't work
When users send the message along with image, the selection should be reset to 0 (same as what we send the message only).
But we prevent to update selection if the text input is not focused, in case users send message + image, the image modal preview will show that makes the composer is blurred
=> the selection is not reset to 0, then the logic up-to-edit is not triggered
We should prevent suggestionsRef.current?.onSelectionChange?.(e);
when the input is not focused only, since the selection is changed actually -> it should be updated
setSelection(e.nativeEvent.selection);
if (!textInputRef.current?.isFocused()) {
return;
}
suggestionsRef.current?.onSelectionChange?.(e);
We can force update the selection in clear function.
Pass clear flag param in
Then use this flag to force update selection in https://github.com/Expensify/App/blob/64cb4ee92b1f4c66e5deb96e23caf47e25423c00/src/pages/home/report/ReportActionCompose/ComposerWithSuggestions/ComposerWithSuggestions.tsx#L512
I think it makes sense to fix this, yes. Basically whether a message has an image or not shouldn't change your ability to hit the up arrow to quickly edit it.
Job added to Upwork: https://www.upwork.com/jobs/~021856262688043659757
Ty Shawn, lets do it!
Triggered auto assignment to Contributor-plus team member for initial proposal review - @jayeshmangwani (External
)
Thanks for the proposal, @Shahidullah-Muffakir. Removing selection.start <= 0
as you suggested would break the current functionality for moving to the first line when pressing the up key in the composer.
Steps to reproduce the issue after applying your change:
Thanks for the proposal, @Shahidullah-Muffakir. Removing
selection.start <= 0
as you suggested would break the current functionality for moving to the first line when pressing the up key in the composer.Steps to reproduce the issue after applying your change:
- Press Command + Space in the composer to add a new line.
- Press the up key.
- Nothing happens, whereas in the current version of the app, pressing the up key in the composer allows the cursor to move to the first line.
@jayeshmangwani , Oh, got it, thanks for explaining that! I could reproduce it now.
Given that, what do you think of the alternative approach I mentioned in my proposal: setting selection.start to 0 whenever a message is sent with an attachment?
Or when we send the comment without or without attachment, this onClear, is called. https://github.com/Expensify/App/blob/be4d7f50949d52aa9f2cb9a8ac495ef19473edde/src/pages/home/report/ReportActionCompose/ComposerWithSuggestions/ComposerWithSuggestions.tsx#L700
we can set the selection.start to 0 here as well as:
setSelection((prevState) => ({ ...prevState, start: 0, end: 0 }));
https://github.com/user-attachments/assets/60273dcc-7c61-48ee-a581-17ee8484bb3c
@daledah I tried adding setSelection
before the isFocused
condition, but I feel this could introduce a regression. Although the issue doesn't consistently reproduce, I've managed to replicate it a few times. Here are the steps:
@
to open the mention suggestion.https://github.com/user-attachments/assets/e9570064-3b7b-435d-b8be-39a65b6f5eb3
@Shahidullah-Muffakir I have a question for this comment: if we add the setSelection((prevState) => ({ ...prevState, start: 0, end: 0 }));
in onClear
, are we not setting setSelection
twice? We’re already calling setSelection(e.nativeEvent.selection)
in ComposerWithSuggestions
.
@Shahidullah-Muffakir I have a question for this comment: if we add the
setSelection((prevState) => ({ ...prevState, start: 0, end: 0 }));
inonClear
, are we not settingsetSelection
twice? We’re already callingsetSelection(e.nativeEvent.selection)
inComposerWithSuggestions
.
@jayeshmangwani , in this part: https://github.com/Expensify/App/blob/be4d7f50949d52aa9f2cb9a8ac495ef19473edde/src/pages/home/report/ReportActionCompose/ComposerWithSuggestions/ComposerWithSuggestions.tsx#L514-L519
the setSelection(e.nativeEvent.selection)
, won't be executed as the !textInputRef.current?.isFocused()
, will be true in the case of sending attachment.
and just to not re-rerun this setSelection((prevState) => ({ ...prevState, start: 0, end: 0 }));
on the onClear function twice for a text only message, we can add check if the input is not focused then run it.
if(selection.start !== 0){
setSelection((prevState) => ({ ...prevState, start: 0, end: 0 }));
}
or
if(!textInputRef.current?.isFocused()){
setSelection((prevState) => ({ ...prevState, start: 0, end: 0 }));
}
Also, I noticed that setSelection((prevState) => ({ ...prevState, start: 0, end: 0 }));
is also being called in the Composer component’s onClear function
here:
https://github.com/Expensify/App/blob/e6b416726fbe7171e84f048a8874c1b9254b6a26/src/components/Composer/implementation/index.tsx#L278
and just to not re-rerun this setSelection((prevState) => ({ ...prevState, start: 0, end: 0 })); on the onClear function twice for a text only message, we can add check if the input is not focused then run it.
Thanks! Let me test this change.
called in the Composer component’s onClear function
Just to confirm, is onClear triggered only for text only message?
Just to confirm, is onClear triggered only for text only message?
No, clear is triggered for all messages, regardless of whether they include attachments or are text-only. https://github.com/Expensify/App/blob/e6b416726fbe7171e84f048a8874c1b9254b6a26/src/components/Composer/implementation/index.tsx#L278
In clear, setSelection({ start: 0, end: 0 })
is called to reset the selection, but it only updates the local state selection
within the Composer component. Since this reset is only applied to Composer's own internal selection state, it doesn’t affect the selection state in ComposerWithSuggestions.
https://github.com/Expensify/App/blob/04402e9f47a77f10b3c2c47fefe0931fbf62e4d4/src/components/Composer/implementation/index.tsx#L63-L68
In ComposerWithSuggestions, we maintain a separate local selection state using which we decide to open the comment edit box if the selection.start <=0,
https://github.com/Expensify/App/blob/e6b416726fbe7171e84f048a8874c1b9254b6a26/src/components/Composer/implementation/index.tsx#L63
This means the selection reset on clear
in Composer
doesn’t propagate to ComposerWithSuggestions
, which is why we need to explicitly update the selection state of ComposerWithSuggestions in the onClear
:
https://github.com/Expensify/App/blob/be4d7f50949d52aa9f2cb9a8ac495ef19473edde/src/pages/home/report/ReportActionCompose/ComposerWithSuggestions/ComposerWithSuggestions.tsx#L700
@Shahidullah-Muffakir While testing your changes, I discovered another bug related to the up-to-edit feature (reproducing on staging as well), which I believe we should address within this issue. Could you confirm if the root cause is the same for message with attachment as well as the bug described below, and whether your proposal will fix it?
Steps to reproduce:
Let me know if your solution will cover this case as well.
https://github.com/user-attachments/assets/4b7891ad-8c9b-4bfa-8dbd-ec4f3a526470
@Shahidullah-Muffakir While testing your changes, I discovered another bug related to the up-to-edit feature (reproducing on staging as well), which I believe we should address within this issue. Could you confirm if the root cause is the same for message with attachment as well as the bug described below, and whether your proposal will fix it?
Steps to reproduce:
- Type a message in the chat, then tap outside the composer to remove focus.
- Press the Send button.
- Tap on the composer again.
- Press the up key. (Expected: It should open the edit mode for the last message, but currently it does nothing.)
Let me know if your solution will cover this case as well.
edit-focus-bug.mov
@jayeshmangwani , Yes it has the same root cause as the issue in the OP, and the proposed solution will work for this as well.
https://github.com/user-attachments/assets/9b61ae19-46a6-423d-8d40-ea579a1c3e4d
@Shahidullah-Muffakir Cool, please add your comments https://github.com/Expensify/App/issues/52319#issuecomment-2470952844 https://github.com/Expensify/App/issues/52319#issuecomment-2474203557 https://github.com/Expensify/App/issues/52319#issuecomment-2475588671 to the main proposal in one place and update the proposal so I can review it again.
@jayeshmangwani, Proposal updated, Thank you.
Hey @Shahidullah-Muffakir, thanks for updating the proposal, and sorry for the back-and-forth. Since this is the main component of the app, I need to test some parts thoroughly, which is why it's taking a bit longer to approve the proposal.
Also, from your proposal, it seems to work fine in testing, but I don't entirely agree with setting setSelection({ start: 0, end: 0 })
in onClear
. The reasons are:
Composer/implementation/index.tsx
, when we send the message and clear the text, only the clear
function is called, and at that time onSelectionChange
won't trigger. So, setting the selection to 0 will only happen from one place.ComposerWithSuggestions component
, when the text is cleared, both onSelectionChange
and onClear
are called. So, setting setSelection
in both places feels a bit odd right now. We should either set setSelection
from onSelectionChange
or from onClear
.No problem, @jayeshmangwani. Regarding the setSelection({ start: 0, end: 0 }) placement, I see your point about the redundancy in calling setSelection in both onClear and onSelectionChange within ComposerWithSuggestions. However, the Composer component itself also handles selection changes in both clear and onSelectionChange. As we are passing onSelectionChange as a prop to Composer component from ComposerWithSuggestions https://github.com/Expensify/App/blob/04402e9f47a77f10b3c2c47fefe0931fbf62e4d4/src/components/Composer/implementation/index.tsx#L277 What do you think about this? I’ll also keep looking .
Composer component itself also handles selection changes in both clear and onSelectionChange
Yes, but in the Composer
component, onSelectionChange
is not triggered when we press the send button. On the other hand, in ComposerWithSuggestions
, both clear
and onSelectionChange
are called when pressing send or when clearing the composer.
Yes, but in the
Composer
component,onSelectionChange
is not triggered when we press the send button.
When we send message the clear function of Composer
component is being called, inside that function onSelectionChange
is also being called.
@jayeshmangwani The issue you mentioned here still happens on staging. I don't think it's my regression
https://github.com/user-attachments/assets/390bc577-c7c2-43d4-a125-6c3463eb12b0
@jliexpensify, @jayeshmangwani Uh oh! This issue is overdue by 2 days. Don't forget to update your issues!
Yes @daledah, I'm also able to reproduce this on staging, so it doesn't appear to be caused by your changes.
Thanks to everyone for the proposals above!
I've tested a few cases, and calling setSelection
before the !textInputRef.current?.isFocused()
condition in onSelectionChange
resolves the issue without causing any problems during testing. Based on this, I suggest we proceed with @daledah's Proposal.
🎀 👀 🎀 C+ reviewed
Triggered auto assignment to @stitesExpensify, see https://stackoverflow.com/c/expensify/questions/7972 for more details.
📣 @daledah 🎉 An offer has been automatically sent to your Upwork account for the Contributor role 🎉 Thanks for contributing to the Expensify app!
Offer link Upwork job Please accept the offer and leave a comment on the Github issue letting us know when we can expect a PR to be ready for review 🧑💻 Keep in mind: Code of Conduct | Contributing 📖
Reviewing
label has been removed, please complete the "BugZero Checklist".
The solution for this issue has been :rocket: deployed to production :rocket: in version 9.0.68-7 and is now subject to a 7-day regression period :calendar:. Here is the list of pull requests that resolve this issue:
If no regressions arise, payment will be issued on 2024-12-07. :confetti_ball:
For reference, here are some details about the assignees on this issue:
@jayeshmangwani @jliexpensify @jayeshmangwani The PR fixing this issue has been merged! The following checklist (instructions) will need to be completed before the issue can be closed. Please copy/paste the BugZero Checklist from here into a new comment on this GH and complete it. If you have the K2 extension, you can simply click: [this button]
If you haven’t already, check out our contributing guidelines for onboarding and email contributors@expensify.com to request to join our Slack channel!
Version Number: 9.0.59-3 Reproducible in staging?: Needs Reproduction Reproducible in production?: Needs Reproduction If this was caught on HybridApp, is this reproducible on New Expensify Standalone?: If this was caught during regression testing, add the test name, ID and link from TestRail: Email or phone of affected tester (no customers): Logs: https://stackoverflow.com/c/expensify/questions/4856 Expensify/Expensify Issue URL: Issue reported by: @quinthar Slack conversation (hyperlinked to channel name): ts_external_expensify_bugs
Action Performed:
Expected Result:
User able to edit the sent message
Actual Result:
Up to edit feature doesn't work
Workaround:
Unknown
Platforms:
Which of our officially supported platforms is this issue occurring on?
Screenshots/Videos
Add any screenshot/video evidence
https://github.com/user-attachments/assets/c85f012b-ca8c-497b-9acf-142f1c5b9a4a
View all open jobs on GitHub
Upwork Automation - Do Not Edit
Issue Owner
Current Issue Owner: @jliexpensify