Skip to content
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

[HOLD for payment 2024-12-07] [$250] The up-to-edit feature doesn't work when the message contains an embedded image. #52319

Closed
1 of 8 tasks
m-natarajan opened this issue Nov 11, 2024 · 35 comments
Assignees
Labels
Awaiting Payment Auto-added when associated PR is deployed to production Bug Something is broken. Auto assigns a BugZero manager. Daily KSv2 External Added to denote the issue can be worked on by a contributor

Comments

@m-natarajan
Copy link

m-natarajan commented Nov 11, 2024

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:

  1. Navigate to any chat
  2. Compose any message and add a attachment
  3. Send the message
  4. Press the up arrow on the keyboard to edit

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?

  • Android: Standalone
  • Android: HybridApp
  • Android: mWeb Chrome
  • iOS: Standalone
  • iOS: HybridApp
  • iOS: mWeb Safari
  • MacOS: Chrome / Safari
  • MacOS: Desktop

Screenshots/Videos

Add any screenshot/video evidence
Recording.737.mp4

View all open jobs on GitHub

Upwork Automation - Do Not Edit
  • Upwork Job URL: https://www.upwork.com/jobs/~021856262688043659757
  • Upwork Job ID: 1856262688043659757
  • Last Price Increase: 2024-11-12
  • Automatic offers:
    • daledah | Contributor | 104956482
Issue OwnerCurrent Issue Owner: @jliexpensify
@m-natarajan m-natarajan added Daily KSv2 Bug Something is broken. Auto assigns a BugZero manager. labels Nov 11, 2024
Copy link

melvin-bot bot commented Nov 11, 2024

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.

@Shahidullah-Muffakir
Copy link
Contributor

Shahidullah-Muffakir commented Nov 11, 2024

Edited by proposal-police: This proposal was edited at 2024-11-14 08:30:02 UTC.

Proposal

Please re-state the problem that we are trying to solve in this issue.

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

What is the root cause of that problem?

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:

if (webEvent.key === CONST.KEYBOARD_SHORTCUTS.ARROW_UP.shortcutKey && selection.start <= 0 && isEmptyComment && !includeChronos) {

What changes do you think we should make in order to solve the problem?

when we send the comment without or without attachment, this onClear, is called.

we can set the selection.start to 0 as :
setSelection({ start: 0, end: 0 });
in this part:

if (!textInputRef.current?.isFocused()) {
return;
}
suggestionsRef.current?.onSelectionChange?.(e);
setSelection(e.nativeEvent.selection);

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:

setSelection({start: 0, end: 0});

clear function in Composer component is triggered for all messages, regardless of whether they include attachments or are text-only.
setSelection({start: 0, end: 0});

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.

const [selection, setSelection] = useState<
| {
start: number;
end?: number;
positionX?: number;
positionY?: number;

In ComposerWithSuggestions, we maintain a separate local selection state using which we decide to open the comment edit box if the selection.start <=0,
const [selection, setSelection] = useState<

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:

@jliexpensify
Copy link
Contributor

@Expensify/design before I make this External, do you want to review this thread and weigh in and confirm this is something we want to change? Shawn has shared thoughts here already. Thanks!

@daledah
Copy link
Contributor

daledah commented Nov 12, 2024

Edited by proposal-police: This proposal was edited at 2024-11-12 04:40:00 UTC.

Proposal

Please re-state the problem that we are trying to solve in this issue.

Up to edit feature doesn't work

What is the root cause of that problem?

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

const onSelectionChange = useCallback(
(e: CustomSelectionChangeEvent) => {
if (!textInputRef.current?.isFocused()) {
return;
}
suggestionsRef.current?.onSelectionChange?.(e);
setSelection(e.nativeEvent.selection);
},
[suggestionsRef],
);

=> the selection is not reset to 0, then the logic up-to-edit is not triggered

if (webEvent.key === CONST.KEYBOARD_SHORTCUTS.ARROW_UP.shortcutKey && selection.start <= 0 && isEmptyComment && !includeChronos) {

What changes do you think we should make in order to solve the problem?

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);

What alternative solutions did you explore? (Optional)

We can force update the selection in clear function.

Pass clear flag param in

onSelectionChange(selectionEvent);

Then use this flag to force update selection in

@shawnborton
Copy link
Contributor

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.

@jliexpensify jliexpensify added the External Added to denote the issue can be worked on by a contributor label Nov 12, 2024
Copy link

melvin-bot bot commented Nov 12, 2024

Job added to Upwork: https://www.upwork.com/jobs/~021856262688043659757

@melvin-bot melvin-bot bot changed the title The up-to-edit feature doesn't work when the message contains an embedded image. [$250] The up-to-edit feature doesn't work when the message contains an embedded image. Nov 12, 2024
@melvin-bot melvin-bot bot added the Help Wanted Apply this label when an issue is open to proposals by contributors label Nov 12, 2024
@jliexpensify
Copy link
Contributor

Ty Shawn, lets do it!

Copy link

melvin-bot bot commented Nov 12, 2024

Triggered auto assignment to Contributor-plus team member for initial proposal review - @jayeshmangwani (External)

@jayeshmangwani
Copy link
Contributor

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:

  1. Press Command + Space in the composer to add a new line.
  2. Press the up key.
  3. 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.

@Shahidullah-Muffakir
Copy link
Contributor

Shahidullah-Muffakir commented Nov 12, 2024

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:

  1. Press Command + Space in the composer to add a new line.
  2. Press the up key.
  3. 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.

we can set the selection.start to 0 here as well as:
setSelection((prevState) => ({ ...prevState, start: 0, end: 0 }));

Untitled.mp4

@jayeshmangwani
Copy link
Contributor

@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:

  1. Go to any workspace chat.
  2. Type @ to open the mention suggestion.
  3. Navigate to the LHN and submit an expense to that workspace (from step 1).
  4. Observe that when returning to the workspace chat, a modal opens—though it shouldn't.
suggestion-reapears.mov

@jayeshmangwani
Copy link
Contributor

@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
Copy link
Contributor

Shahidullah-Muffakir commented Nov 13, 2024

@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.

@jayeshmangwani , in this part:

if (!textInputRef.current?.isFocused()) {
return;
}
suggestionsRef.current?.onSelectionChange?.(e);
setSelection(e.nativeEvent.selection);

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:

setSelection({start: 0, end: 0});

@jayeshmangwani
Copy link
Contributor

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.

@jayeshmangwani
Copy link
Contributor

called in the Composer component’s onClear function

Just to confirm, is onClear triggered only for text only message?

@Shahidullah-Muffakir
Copy link
Contributor

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.

setSelection({start: 0, end: 0});

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.

const [selection, setSelection] = useState<
| {
start: number;
end?: number;
positionX?: number;
positionY?: number;

In ComposerWithSuggestions, we maintain a separate local selection state using which we decide to open the comment edit box if the selection.start <=0,
const [selection, setSelection] = useState<

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:

@jayeshmangwani
Copy link
Contributor

@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:

  1. Type a message in the chat, then tap outside the composer to remove focus.
  2. Press the Send button.
  3. Tap on the composer again.
  4. 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

@Shahidullah-Muffakir
Copy link
Contributor

@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:

  1. Type a message in the chat, then tap outside the composer to remove focus.
  2. Press the Send button.
  3. Tap on the composer again.
  4. 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.

Screen.Recording.2024-11-14.at.1.25.53.PM.mov

@jayeshmangwani
Copy link
Contributor

@Shahidullah-Muffakir Cool, please add your comments #52319 (comment) #52319 (comment) #52319 (comment) to the main proposal in one place and update the proposal so I can review it again.

@Shahidullah-Muffakir
Copy link
Contributor

@jayeshmangwani, Proposal updated, Thank you.

@jayeshmangwani
Copy link
Contributor

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:

  1. In 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.
  2. For the 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.

@Shahidullah-Muffakir
Copy link
Contributor

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

onSelectionChange(selectionEvent);

What do you think about this? I’ll also keep looking .

@jayeshmangwani
Copy link
Contributor

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.

@melvin-bot melvin-bot bot added the Overdue label Nov 18, 2024
@jayeshmangwani
Copy link
Contributor

Yes @daledah, I'm also able to reproduce this on staging, so it doesn't appear to be caused by your changes.

@melvin-bot melvin-bot bot removed the Overdue label Nov 18, 2024
@jayeshmangwani
Copy link
Contributor

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

Copy link

melvin-bot bot commented Nov 18, 2024

Triggered auto assignment to @stitesExpensify, see https://stackoverflow.com/c/expensify/questions/7972 for more details.

@melvin-bot melvin-bot bot removed the Help Wanted Apply this label when an issue is open to proposals by contributors label Nov 18, 2024
Copy link

melvin-bot bot commented Nov 18, 2024

📣 @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 📖

@melvin-bot melvin-bot bot added Reviewing Has a PR in review Weekly KSv2 and removed Daily KSv2 labels Nov 19, 2024
@daledah
Copy link
Contributor

daledah commented Nov 19, 2024

@jayeshmangwani PR is ready.

@melvin-bot melvin-bot bot added Weekly KSv2 Awaiting Payment Auto-added when associated PR is deployed to production and removed Weekly KSv2 labels Nov 30, 2024
@melvin-bot melvin-bot bot changed the title [$250] The up-to-edit feature doesn't work when the message contains an embedded image. [HOLD for payment 2024-12-07] [$250] The up-to-edit feature doesn't work when the message contains an embedded image. Nov 30, 2024
Copy link

melvin-bot bot commented Nov 30, 2024

Reviewing label has been removed, please complete the "BugZero Checklist".

@melvin-bot melvin-bot bot removed the Reviewing Has a PR in review label Nov 30, 2024
Copy link

melvin-bot bot commented Nov 30, 2024

The solution for this issue has been 🚀 deployed to production 🚀 in version 9.0.68-7 and is now subject to a 7-day regression period 📆. Here is the list of pull requests that resolve this issue:

If no regressions arise, payment will be issued on 2024-12-07. 🎊

For reference, here are some details about the assignees on this issue:

Copy link

melvin-bot bot commented Nov 30, 2024

@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]

@jliexpensify
Copy link
Contributor

jliexpensify commented Dec 4, 2024

Payment Summary

Upwork job

@jayeshmangwani
Copy link
Contributor

BugZero Checklist:

  • [Contributor] Classify the bug:
Bug classification

Source of bug:

  • 1a. Result of the original design (eg. a case wasn't considered)
  • 1b. Mistake during implementation
  • 1c. Backend bug
  • 1z. Other:

Where bug was reported:

  • 2a. Reported on production (eg. bug slipped through the normal regression and PR testing process on staging)
  • 2b. Reported on staging (eg. found during regression or PR testing)
  • 2d. Reported on a PR
  • 2z. Other:

Who reported the bug:

  • 3a. Expensify user
  • 3b. Expensify employee
  • 3c. Contributor
  • 3d. QA
  • 3z. Other:
  • [Contributor] The offending PR has been commented on, pointing out the bug it caused and why, so the author and reviewers can learn from the mistake.

    Link to comment: Modify optimistic data to support new text+attachment messages #39007 (comment)

  • [Contributor] If the regression was CRITICAL (e.g. interrupts a core flow) A discussion in #expensify-open-source has been started about whether any other steps should be taken (e.g. updating the PR review checklist) in order to catch this type of bug sooner.

    Link to discussion: N/A

  • [Contributor] If it was decided to create a regression test for the bug, please propose the regression test steps using the template below to ensure the same bug will not reach production again.

Regression Test Proposal

  1. Open any chat.
  2. Send a message with an attachment.
  3. Wait until the attachment is sent.
  4. Press the Up key.
  5. Verify that the Edit composer is displayed.

Do we agree 👍 or 👎

@melvin-bot melvin-bot bot added Daily KSv2 and removed Weekly KSv2 labels Dec 7, 2024
@jliexpensify
Copy link
Contributor

Paid and job closed.

@jayeshmangwani - here's the summary for your request.

@garrettmknight
Copy link
Contributor

$250 approved for @jayeshmangwani

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Awaiting Payment Auto-added when associated PR is deployed to production Bug Something is broken. Auto assigns a BugZero manager. Daily KSv2 External Added to denote the issue can be worked on by a contributor
Projects
None yet
Development

No branches or pull requests

8 participants