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 2023-08-02] [$1000] The cursor position is not at the end of the message when editing the welcome message #21523

Closed
1 of 6 tasks
kavimuru opened this issue Jun 25, 2023 · 63 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 Engineering External Added to denote the issue can be worked on by a contributor

Comments

@kavimuru
Copy link

kavimuru commented Jun 25, 2023

If you haven’t already, check out our contributing guidelines for onboarding and email contributors@expensify.com to request to join our Slack channel!


Action Performed:

  1. Create a room
  2. Go to the room details > settings and select "Welcome Message"
  3. Enter a message and click on "Save"
  4. Once again, click on the welcome message for editing

Expected Result:

The cursor position should be at the end of the message when editing the welcome message

Actual Result:

The cursor is at the start of the message

Workaround:

Can the user still use Expensify without this being fixed? Have you informed them of the workaround?

Platforms:

Which of our officially supported platforms is this issue occurring on?

  • Android / native
  • Android / Chrome
  • iOS / native
  • iOS / Safari
  • MacOS / Chrome / Safari
  • MacOS / Desktop

Version Number: 1.3.32-5
Reproducible in staging?: y
Reproducible in production?: y
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
Notes/Photos/Videos: Any additional supporting documentation

screen-recording-2023-06-20-at-24757-pm_rWeBf4YW.mp4
Recording.5122.mp4

Expensify/Expensify Issue URL:
Issue reported by: @ayazhussain79
Slack conversation: https://expensify.slack.com/archives/C049HHMV9SM/p1687255221337649

View all open jobs on GitHub

Upwork Automation - Do Not Edit
  • Upwork Job URL: https://www.upwork.com/jobs/~01c431cd4d3b60ebff
  • Upwork Job ID: 1674581546420617216
  • Last Price Increase: 2023-07-14
@kavimuru kavimuru added Daily KSv2 Bug Something is broken. Auto assigns a BugZero manager. labels Jun 25, 2023
@melvin-bot
Copy link

melvin-bot bot commented Jun 25, 2023

Triggered auto assignment to @sakluger (Bug), see https://stackoverflow.com/c/expensify/questions/14418 for more details.

@melvin-bot
Copy link

melvin-bot bot commented Jun 25, 2023

Bug0 Triage Checklist (Main S/O)

  • This "bug" occurs on a supported platform (ensure Platforms in OP are ✅)
  • This bug is not a duplicate report (check E/App issues and #expensify-bugs)
    • If it is, comment with a link to the original report, close the issue and add any novel details to the original issue instead
  • This bug is reproducible using the reproduction steps in the OP. S/O
    • If the reproduction steps are clear and you're unable to reproduce the bug, check with the reporter and QA first, then close the issue.
    • If the reproduction steps aren't clear and you determine the correct steps, please update the OP.
  • This issue is filled out as thoroughly and clearly as possible
    • Pay special attention to the title, results, platforms where the bug occurs, and if the bug happens on staging/production.
  • I have reviewed and subscribed to the linked Slack conversation to ensure Slack/Github stay in sync

@chiragxarora
Copy link
Contributor

chiragxarora commented Jun 25, 2023

Proposal

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

The cursor position is not at the end of the message when editing the welcome message

What is the root cause of that problem?

Root cause of the issue is that we have not calculated the cursor position by selection property which by default is at zero. This leads to the rendering of cursor at the beginning when we focus it using the ref.

<TextInput
inputID="welcomeMessage"
label={props.translate('welcomeMessagePage.welcomeMessage')}
multiline
numberOfLines={10}
maxLength={CONST.MAX_COMMENT_LENGTH}
ref={(el) => (welcomeMessageInputRef.current = el)}
value={welcomeMessage}
onChangeText={handleWelcomeMessageChange}
autoCapitalize="none"
textAlignVertical="top"
/>

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

First of all we need a state in the component to keep the track of caret position which we can use to update the selection.
We could create a selection state using react hooks like this:

const [selection, setSelection] = useState({start: n, end: n});

Now we need to set an initial positon of caret from where the cursor will start when open the welcome message dalogue.
For this, we already have a state called welcomeMessage which is storing the previous welcome message received from props. So we can use that to set initial caret position.

Now we have a state object which keeps the initial caret position, so now while editing the welcome message when user clicks anywhere inside the <TextInput/> to change the caret position, we can update our state by using onSelectionChange prop. This way we will always keep track of latest caret position.

And now since we have added a util called focusAndUpdateMultiline, we can directly use that once the transition ends and ref is initialised

`onEntryTransitionEnd={() => if(inputRef && inputRef.current) focusAndUpdateMultiline(inputRef.current);}

UPDATE: (auto focus on reload)

Focus mechanism and cursor aren't set on reload because the TextInput is not mounted till the time when we call our focus method.
In order to solve this, we should go for a more logical approach rather than using timeouts.

We should run a side-effect when our <TextInput/> has mounted and for this we can track the changes happening on our inputRef.current object.

useEffect(() => {
    if(welcomeMessageInputRef.current) {
        // now focus
    }
}, [welcomeMessageInputRef.current]);

Final code changes

function ReportWelcomeMessagePage(props) {
 ...................
  useEffect(() => {
    if(welcomeMessageInputRef.current) {
        focusAndUpdateMultilineInputRange(welcomeMessageInputRef.current);
    }
  }, [welcomeMessageInputRef.current]);
 ...................
  <TextInput
      inputID="welcomeMessage"
      label={props.translate('welcomeMessagePage.welcomeMessage')}
      multiline
      numberOfLines={10}
      maxLength={CONST.MAX_COMMENT_LENGTH}
      ref={(el) => (welcomeMessageInputRef.current = el)}
      value={welcomeMessage}
      onChangeText={handleWelcomeMessageChange}
      autoCapitalize="none"
      textAlignVertical="top"
  />

NOTE: no other proposal proposed this solution till the time of final edit

Updated Results
bandicam.2023-07-03.22-12-29-395.mp4

What alternative solutions did you explore? (Optional)

We can achieve the similar results by using a callback hook too
Or
In the main solution, we can even omit the ref from dependent array after passing the welcomeMessageInputRef directly to the ref prop

@sakluger
Copy link
Contributor

@Expensify/design do you think this is a bug? I'm leaning towards yes, but wanted a second opinion.

@shawnborton
Copy link
Contributor

Wow, what a find. Yeah, I guess it makes sense that the cursor starts off at the end as opposed to the beginning.

@shawnborton shawnborton self-assigned this Jun 27, 2023
@melvin-bot melvin-bot bot added the Overdue label Jun 29, 2023
@sakluger
Copy link
Contributor

Alright let's do this thing. Adding the external label.

@melvin-bot melvin-bot bot removed the Overdue label Jun 30, 2023
@sakluger sakluger added the External Added to denote the issue can be worked on by a contributor label Jun 30, 2023
@melvin-bot melvin-bot bot changed the title The cursor position is not at the end of the message when editing the welcome message [$1000] The cursor position is not at the end of the message when editing the welcome message Jun 30, 2023
@melvin-bot
Copy link

melvin-bot bot commented Jun 30, 2023

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

@melvin-bot melvin-bot bot added the Help Wanted Apply this label when an issue is open to proposals by contributors label Jun 30, 2023
@melvin-bot
Copy link

melvin-bot bot commented Jun 30, 2023

Current assignee @sakluger is eligible for the External assigner, not assigning anyone new.

@melvin-bot
Copy link

melvin-bot bot commented Jun 30, 2023

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

@hoangzinh
Copy link
Contributor

hoangzinh commented Jun 30, 2023

Proposal

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

The cursor position is not at the end of the message when editing the welcome message

What is the root cause of that problem?

In the focus logic when the Report welcome message loaded, we just call focus function:

onEntryTransitionEnd={() => {
if (!welcomeMessageInputRef.current) {
return;
}
welcomeMessageInputRef.current.focus();
}}

It seems we forgot to set selection range to make the cursor position when the message has value like other places. I.e:

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

We can't do same things we did for Workspace invite message page here because when we visit by direct link, although onEntryTransitionEnd callback of ScreenWrapper is triggered, the inputRef is still null, sometime.

So my approach is:
I think the condition to focus on the Input is: when the screen animation end AND the inputRef is set. Currently, those 2 states are in 2 different components and different callbacks so we need to store those states in a same place, and trigger focus when those 2 states are true (or conditions are meet). In order to do that, I think about a custom hook, this hook will store those 2 states, and expose setters to set those 2 states to true when the ScreenWrapper onEntryTransitionEnd or Input ref setter callback

Code reference
const useFocusInputRangeWhenReady = (inputRef) => {
    const [isInputRefReady, setIsInputRefReady] = useState(false);
    const [didInputTransitionEnd, setDidInputTransitionEnd] = useState(false);

    useEffect(() => {
        if (!isInputRefReady || !didInputTransitionEnd) {
            return;
        }

        focusAndUpdateMultilineInputRange(inputRef.current);
    }, [isInputRefReady, didInputTransitionEnd, inputRef]);

    return { setIsInputRefReady, setDidInputTransitionEnd}
}
  • In ScreenWrapper onEntryTransitionEnd
onEntryTransitionEnd={() => {
    setDidInputTransitionEnd(true);
}}
  • Input ref setter callback
ref={(el) => {
    welcomeMessageInputRef.current = el;
    setIsInputRefReady(Boolean(welcomeMessageInputRef.current));
}}
Recording result
Screen.Recording.2023-07-10.at.18.30.40.mov

What alternative solutions did you explore? (Optional)

Alternative 1:
If we don't prefer custom hook or think it's complicated. I think about another option. My assumption is based on this as well:

I think the condition to focus on the Input is: when the screen animation end AND the inputRef is set

So need to put focus code in 2 places, and ensure in each place, the 2 conditions above match:

if (!welcomeMessageInputRef.current && el && didScreenTransitionEnd) {
    focusAndUpdateMultilineInputRange(el);
}

Alternative 2:
If we don't care about the reload case, we can just do the same we did for Task description page by using this util focusAndUpdateMultilineInputRange. This util will help us do 3 things: focus, set cursor at the end and automatically scroll the input field to the end for multiple line inputs.

We will use above util and replace for this line here

@melvin-bot melvin-bot bot added the Overdue label Jul 3, 2023
@fabOnReact
Copy link
Contributor

fabOnReact commented Jul 3, 2023

I investigated the issue. Seems to be the expected behaviour of react-navigation.

https://reactnavigation.org/docs/navigation-lifecycle/#example-scenario
snack https://snack.expo.dev/@fabrizio.bertoglio/navigation-prop-reference-|-react-navigation
issue react-navigation/react-navigation#1953

@melvin-bot
Copy link

melvin-bot bot commented Jul 3, 2023

Looks like something related to react-navigation may have been mentioned in this issue discussion.

As a reminder, please make sure that all proposals are not workarounds and that any and all attempt to fix the issue holistically have been made before proceeding with a solution. Proposals to change our DeprecatedCustomActions.js files should not be accepted.

Feel free to drop a note in #expensify-open-source with any questions.

@shawnborton
Copy link
Contributor

Not overdue, still looking at proposals.

@melvin-bot melvin-bot bot removed the Overdue label Jul 3, 2023
@mollfpr
Copy link
Contributor

mollfpr commented Jul 3, 2023

@chiragxarora It has the same result as using focusAndUpdateMultilineInputRange, so I want to keep using it.

@hoangzinh The input needs to be focused after refreshing the page.

@chiragxarora
Copy link
Contributor

chiragxarora commented Jul 3, 2023

Actually at the time I wrote the proposal, this focusAndUpdateMultilineInputRange util wasn't there. Its added few days back, so I'll update my proposal according to that.

@mollfpr

@hoangzinh

This comment was marked as outdated.

@chiragxarora
Copy link
Contributor

chiragxarora commented Jul 3, 2023

I've updated my proposal #21523 (comment) too for the reloading case, pls check @mollfpr

@hoangzinh
Copy link
Contributor

@mollfpr I just updated my proposal #21523 (comment) to cover the case that you mentioned above.

@sakluger
Copy link
Contributor

I just tested on staging and confirmed that this bug is still reproduceable. @danieldoglas do you agree that we should assign @hoangzinh?

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

melvin-bot bot commented Jul 18, 2023

📣 @mollfpr 🎉 An offer has been automatically sent to your Upwork account for the Reviewer role 🎉 Thanks for contributing to the Expensify app!

Upwork job

@melvin-bot
Copy link

melvin-bot bot commented Jul 18, 2023

📣 @hoangzinh 🎉 An offer has been automatically sent to your Upwork account for the Contributor role 🎉 Thanks for contributing to the Expensify app!

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

melvin-bot bot commented Jul 18, 2023

📣 @ayazhussain79 We're missing your Upwork ID to automatically send you an offer for the Reporter role.
Once you apply to the Upwork job, your Upwork ID will be stored and you will be automatically hired for future jobs!

@jasperhuangg
Copy link
Contributor

Yep, #22586 is unrelated to this issue, so we should continue with the triage process.

@hoangzinh
Copy link
Contributor

@mollfpr @danieldoglas Thanks for accepting my proposal. The PR is ready #23162. Please help me review it. Thanks

@sakluger
Copy link
Contributor

This one just got merged, thanks everyone! Looks like it was merged in 4 business days.

@melvin-bot melvin-bot bot added Weekly KSv2 Awaiting Payment Auto-added when associated PR is deployed to production and removed Daily KSv2 Weekly KSv2 labels Jul 26, 2023
@melvin-bot melvin-bot bot changed the title [$1000] The cursor position is not at the end of the message when editing the welcome message [HOLD for payment 2023-08-02] [$1000] The cursor position is not at the end of the message when editing the welcome message Jul 26, 2023
@melvin-bot melvin-bot bot removed the Reviewing Has a PR in review label Jul 26, 2023
@melvin-bot
Copy link

melvin-bot bot commented Jul 26, 2023

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

@melvin-bot
Copy link

melvin-bot bot commented Jul 26, 2023

The solution for this issue has been 🚀 deployed to production 🚀 in version 1.3.45-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 2023-08-02. 🎊

After the hold period is over and BZ checklist items are completed, please complete any of the applicable payments for this issue, and check them off once done.

  • External issue reporter
  • Contributor that fixed the issue
  • Contributor+ that helped on the issue and/or PR

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

As a reminder, here are the bonuses/penalties that should be applied for any External issue:

  • Merged PR within 3 business days of assignment - 50% bonus
  • Merged PR more than 9 business days after assignment - 50% penalty

@melvin-bot
Copy link

melvin-bot bot commented Jul 26, 2023

BugZero Checklist: The PR fixing this issue has been merged! The following checklist (instructions) will need to be completed before the issue can be closed:

  • [@mollfpr] The PR that introduced the bug has been identified. Link to the PR:
  • [@mollfpr] 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:
  • [@mollfpr] A discussion in #expensify-bugs 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:
  • [@mollfpr] Determine if we should create a regression test for this bug.
  • [@mollfpr] If we decide to create a regression test for the bug, please propose the regression test steps to ensure the same bug will not reach production again.
  • [@sakluger] Link the GH issue for creating/updating the regression test once above steps have been agreed upon:

@mollfpr
Copy link
Contributor

mollfpr commented Aug 3, 2023

[@mollfpr] The PR that introduced the bug has been identified. Link to the PR:

#18662

[@mollfpr] 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:

https://github.com/Expensify/App/pull/18662/files#r1283428248

[@mollfpr] A discussion in #expensify-bugs 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:

The regression test should be enough.

[@mollfpr] Determine if we should create a regression test for this bug.
[@mollfpr] If we decide to create a regression test for the bug, please propose the regression test steps to ensure the same bug will not reach production again.

On Web/mWeb

  1. Create a room
  2. Go to the room details > settings and select "Welcome Message"
  3. Enter a message and click on "Save"
  4. Once again, click on the welcome message for editing
  5. Verify that the cursor position should be at the end of the message when editing the welcome message
  6. Reload the page
  7. Verify that the cursor position should be at the end of the message when editing the welcome message

On Desktop/Native apps

  1. Create a room
  2. Go to the room details > settings and select "Welcome Message"
  3. Enter a message and click on "Save"
  4. Once again, click on the welcome message for editing
  5. Verify that the cursor position should be at the end of the message when editing the welcome message

@sakluger
Copy link
Contributor

sakluger commented Aug 4, 2023

Summarizing payouts for this issue:

Bug reporter: @ayazhussain79 $250 (hired on Upwork)
Contributor: @hoangzinh $1000 (hired on Upwork)
Contributor+: @mollfpr $1000 (hired on Upwork)

Upwork job: https://www.upwork.com/jobs/~01c431cd4d3b60ebff

@sakluger
Copy link
Contributor

sakluger commented Aug 4, 2023

@ayazhussain79 I forgot to send you an offer previously, sorry about that! I just sent you a contract through Upwork, please let me know once you have accepted the offer.

@ayazhussain79
Copy link
Contributor

@sakluger offer accepted, Thank you

@sakluger
Copy link
Contributor

sakluger commented Aug 4, 2023

Thanks @ayazhussain79!

@sakluger sakluger closed this as completed Aug 4, 2023
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 Engineering External Added to denote the issue can be worked on by a contributor
Projects
None yet
Development

No branches or pull requests

10 participants