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

[$1000] selected country does not show on opening Country selection page #23768

Closed
1 of 6 tasks
kavimuru opened this issue Jul 27, 2023 · 34 comments
Closed
1 of 6 tasks
Assignees
Labels
Bug Something is broken. Auto assigns a BugZero manager. External Added to denote the issue can be worked on by a contributor Reviewing Has a PR in review Weekly KSv2

Comments

@kavimuru
Copy link

kavimuru commented Jul 27, 2023

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:

  1. go to Settings > Profile > Personal details > Home address > Country
  2. select any country which will redirects to Home address
  3. again click on country which will auto populate country name
  4. remove the country name from input field and click on back button
  5. again click on country

Expected Result:

selected country name should show on opening Country selection page

Actual Result:

selected country does not show on opening Country selection page

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.46-1
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-07-27.at.12.56.03.PM.mov
Recording.1377.mp4

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

View all open jobs on GitHub

Upwork Automation - Do Not Edit
  • Upwork Job URL: https://www.upwork.com/jobs/~019d2209c62f7876f0
  • Upwork Job ID: 1684883255023452160
  • 2023-07-28
  • Automatic offers:
    • s77rt | Reviewer | 25857060
    • joh42 | Contributor | 25857061
    • gadhiyamanan | Reporter | 25857063
@kavimuru kavimuru added Daily KSv2 Bug Something is broken. Auto assigns a BugZero manager. labels Jul 27, 2023
@dukenv0307
Copy link
Contributor

Proposal

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

Selected country does not show on opening Country selection page

What is the root cause of that problem?

When we select any country and open the modal again, useEffect is triggered by the change of value prop.

But when we edit the text input, close the modal, and open it again useEffect isn't triggered because all dependencies of this don't change

useEffect(() => {
setSearchValue(lodashGet(allCountries, value, ''));
}, [value, allCountries]);

And then the text input displays the value that we edited before we closed the modal

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

We should add isPickerVisible as a dependency of useEffect to reset the searchValue state every time we open the modal

useEffect(() => {
setSearchValue(lodashGet(allCountries, value, ''));
}, [value, allCountries]);

We also should check and fix other picker's modals if these have the same problem.

What alternative solutions did you explore? (Optional)

We also can reset the searchValue state in hidePickerModal function

https://github.com/Expensify/App/blob/ac74ab9cb25a55e2d042feee24846d5cb7155239/src/components/CountryPicker/index.js#L46-48

@melvin-bot
Copy link

melvin-bot bot commented Jul 27, 2023

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

@melvin-bot
Copy link

melvin-bot bot commented Jul 27, 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

@dylanexpensify dylanexpensify added the External Added to denote the issue can be worked on by a contributor label Jul 28, 2023
@melvin-bot melvin-bot bot changed the title selected country does not show on opening Country selection page [$1000] selected country does not show on opening Country selection page Jul 28, 2023
@melvin-bot
Copy link

melvin-bot bot commented Jul 28, 2023

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

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

melvin-bot bot commented Jul 28, 2023

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

@melvin-bot
Copy link

melvin-bot bot commented Jul 28, 2023

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

@BhuvaneshPatil
Copy link
Contributor

BhuvaneshPatil commented Jul 28, 2023

Proposal

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

selected country does not show on opening Country selection page

What is the root cause of that problem?

In AddressPage, CountryPicker component is never unmounted. When we click on country we only change isPickerVisible state from false to true and vice versa. And as that component is never unmounted we are not resetting the state.

AS we have not added isPickerVisible in dependency array, we are expecting that state would be set while using (defining state) useState -

const [searchValue, setSearchValue] = useState(lodashGet(allCountries, value, ''));
,
that would only happen if component is remounts.

Without opening -
Screenshot 2023-07-28 at 5 47 39 PM

When opened -
Screenshot 2023-07-28 at 5 48 25 PM

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

We shall add isPickerVisible to useEffect dependency array.

as mentioned by @s77rt , it will cause un-necessary render, we shall clear the search value when we dismiss the modal.
i.e - hidePickerModal, this is because it will also handle the case when we select the state/country. And once we hide the modal, we are sure that the search value won't be needed.

Same can be done for StatePicker component.
This issue solves -
#23792

What alternative solutions did you explore? (Optional)

@joh42
Copy link
Contributor

joh42 commented Jul 28, 2023

Proposal

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

The selected country in the country picker modal remains cleared after closing and reopening it.

What is the root cause of that problem?

searchValue remains cleared when the modal is reopened.

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

I suggest we set the search value in showPickerModal() using setSearchValue(lodashGet(allCountries, value, ''));

const showPickerModal = () => {
setIsPickerVisible(true);
};

I acknowledge that this is similar to other proposed solutions. The difference is that we only run setSearchValue when opening the modal, as opposed to both when opening and closing it.

What alternative solutions did you explore? (Optional)

@s77rt
Copy link
Contributor

s77rt commented Jul 28, 2023

@dukenv0307 Thanks for the proposal. Your RCA is about right. The solution makes sense but I think we should avoid adding state variables to useEffect dependencies because this causes an extra unnecessary render.

// Pattern A
setFoo(5);
setBar(10);
// Pattern B
useEffect(() => setBar(10), [foo]);
setFoo(5);

Pattern A will result in 1 render while Pattern B will result in 2 renders. We use Pattern B only when we need to setBar after foo is guaranteed to be set. - This is not the case here, we don't need to wait for isPickerVisible before setting searchValue.

@s77rt
Copy link
Contributor

s77rt commented Jul 28, 2023

@BhuvaneshPatil Thanks for the proposal. I think it's the same as @dukenv0307's proposal.

@dukenv0307
Copy link
Contributor

@s77rt To avoid this I think we can remove the useEffect and only set default value when we open the picker.

@s77rt
Copy link
Contributor

s77rt commented Jul 28, 2023

@joh42 Thanks for the proposal. Your RCA does not say much but it's actually correct, searchValue remains cleared because once we clear it, we simply do nothing and it stays cleared. The suggested solution looks good to me.

🎀 👀 🎀 C+ reviewed
Link to proposal

@melvin-bot
Copy link

melvin-bot bot commented Jul 28, 2023

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

@s77rt
Copy link
Contributor

s77rt commented Jul 28, 2023

@dukenv0307 Thanks for the update but that's actually what @joh42 already suggested.

@dukenv0307
Copy link
Contributor

dukenv0307 commented Jul 29, 2023

@s77rt I think that is an improvement that we can do in the PR.

@s77rt
Copy link
Contributor

s77rt commented Jul 29, 2023

@dukenv0307

If the first solution was

useEffect(() => {
    ...
}, [isPickerVisible]);

and the second was

useEffect(() => {
    if (!isPickerVisible) {
        return;
    }
    ...
}, [isPickerVisible]);

That would be an optimisation. But in our case the first solution uses useEffect while the second solution does not. I think that's enough to distinguish a new approach given the issue simplicity.

@dukenv0307
Copy link
Contributor

I just learned that maybe we will refactor the country picker and state picker modal as a single page in this issue #23725. If that happens, maybe this issue will be fixed, so I think we should hold this issue until the refactoring is completed.

@MariaHCD
Copy link
Contributor

For #23725, I don't think the fix will be refactoring the country picker and state picker as a single page.

So I think we can go ahead with fixing this issue.

cc: @mountiny

@mountiny
Copy link
Contributor

Yep I agree that we should not be refactoring this to two pages unless thats the only possible solution

@MariaHCD
Copy link
Contributor

Cool, so let's go ahead with @joh42's proposal as per @s77rt's recommendation.

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

melvin-bot bot commented Jul 31, 2023

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

Offer link
Upwork job

@melvin-bot
Copy link

melvin-bot bot commented Jul 31, 2023

📣 @joh42 🎉 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
Copy link

melvin-bot bot commented Jul 31, 2023

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

Offer link
Upwork job

@joh42
Copy link
Contributor

joh42 commented Jul 31, 2023

Thanks! You can expect a PR to be ready for review tomorrow.

@joh42
Copy link
Contributor

joh42 commented Aug 1, 2023

As mentioned by @BhuvaneshPatil, this exact issue is present in the state selector:

Screen.Recording.2023-08-01.at.23.44.24.mov

I'll fix both while I'm at it

@joh42
Copy link
Contributor

joh42 commented Aug 1, 2023

Please note: the state picker is broken in Storybook due to an issue with HeaderWithBackButton that I have reported here. This issue exists on staging. As suggested by Jack Nam I still marked the Storybook checkbox as completed, since that issue is not caused by this PR.

@melvin-bot melvin-bot bot added Reviewing Has a PR in review Weekly KSv2 and removed Daily KSv2 labels Aug 1, 2023
@joh42
Copy link
Contributor

joh42 commented Aug 1, 2023

The PR is ready for review @s77rt

@melvin-bot
Copy link

melvin-bot bot commented Aug 2, 2023

🎯 ⚡️ Woah @s77rt / @joh42, great job pushing this forwards! ⚡️

The pull request got merged within 3 working days of assignment, so this job is eligible for a 50% #urgency bonus 🎉

  • when @joh42 got assigned: 2023-07-31 13:23:02 Z
  • when the PR got merged: 2023-08-02 18:00:43 UTC

On to the next one 🚀

@dylanexpensify
Copy link
Contributor

Great work!

@dylanexpensify
Copy link
Contributor

Hmm, I think a payment is due - @joh42 @s77rt did you both apply to upwork?

@s77rt
Copy link
Contributor

s77rt commented Aug 18, 2023

@dylanexpensify No payment is due for me here. Payment will be handled in #17548 as this is a regression.

@joh42
Copy link
Contributor

joh42 commented Aug 21, 2023

@dylanexpensify I got an offer automatically (this is my Upwork profile https://www.upwork.com/freelancers/~01c600f0d690c3dfe1)

@joh42
Copy link
Contributor

joh42 commented Aug 23, 2023

Just to be clear @dylanexpensify, while I'm hired for the Upwork job already, I haven't actually been paid

@dylanexpensify
Copy link
Contributor

Payments sent!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Bug Something is broken. Auto assigns a BugZero manager. External Added to denote the issue can be worked on by a contributor Reviewing Has a PR in review Weekly KSv2
Projects
None yet
Development

No branches or pull requests

8 participants