You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
Repository navigation
[HOLD for payment - waiting on deploy][$250] Opening Two-Factor Authentication settings causes two duplicate API requests for EnableTwoFactorAuth #48034
Edited by proposal-police: This proposal was edited at 2024-08-28 16:13:58 UTC.
Proposal
Please re-state the problem that we are trying to solve in this issue.
Opening Two-Factor Authentication settings causes two duplicate API requests for EnableTwoFactorAuth
What is the root cause of that problem?
The behavior you're seeing, where not just the two-factor authentication call but all calls in useEffect are running twice, is due to React's Strict Mode. This change was introduced in this PR and is only in the development environment. We do not see this behavior in the production build.
What changes do you think we should make in order to solve the problem?
I prefer turning off Strict Mode, as introduced in this PR This way, development and production environments will behave the same.
Note: StrictMode is not needed for concurrent react to work but it is much safer to use it.
What alternative solutions did you explore? (Optional)
We can create a ref and then in useEffect we can early return if it's already mounted. With the implementation of useRef, we ensure that API calls within useEffect are made only once, even in development mode with React's Strict Mode enabled. This method prevents multiple invocations of the effect due to Strict Mode's behavior.
Thanks for the investigation @Nodebrute. I think the thing that I really dislike about that is now dev is a very different environment than production, which makes testing and development much more difficult. We are being forced into some weird patterns (using a bunch of useRef) to try and get development to work more like we expect production to work.
Do you know if React is planning to make production work in this concurrent mode like dev is running in? I guess that would return it to an apples-to-apples situation at some point, which is better, but I really don't like having to guess "does this only happen in dev or not".
I'm going to assign this to external and get a C+ to review your proposal to implement (because even though it only happens in dev, it messed me up enough that I think it's worth fixing).
changed the title [-]Opening Two-Factor Authentication settings causes two duplicate API requests for EnableTwoFactorAuth[/-][+][$250] Opening Two-Factor Authentication settings causes two duplicate API requests for EnableTwoFactorAuth[/+]on Aug 28, 2024
changed the title [-][$250] Opening Two-Factor Authentication settings causes two duplicate API requests for EnableTwoFactorAuth[/-][+][HOLD for payment][$250] Opening Two-Factor Authentication settings causes two duplicate API requests for EnableTwoFactorAuth[/+]on Sep 10, 2024
changed the title [-][HOLD for payment][$250] Opening Two-Factor Authentication settings causes two duplicate API requests for EnableTwoFactorAuth[/-][+][HOLD for payment - waiting on deploy][$250] Opening Two-Factor Authentication settings causes two duplicate API requests for EnableTwoFactorAuth[/+]on Sep 12, 2024
@mollfpr / @tgolen, I'm reviewing the linked PR to calculate the payment date, but I'm having trouble finding what I'm looking for. On #48722, I see it approved and merged but not deployed. I see our internal SO articles refer to using the merge date to calculate the regression threshold window, but without a deploy, I don't think we can really test for regressions. Can you help me sort out the date so I don't hold this one up?
@johncschuster I think we don't need a regression step since it's only affecting the development side and it's knowingly a feature from React but we happen not to need it yet.
Activity
melvin-bot commentedon Aug 26, 2024
Current assignee @tgolen is eligible for the AutoAssignerNewDotQuality assigner, not assigning anyone new.
melvin-bot commentedon Aug 26, 2024
Triggered auto assignment to @johncschuster (
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.Nodebrute commentedon Aug 26, 2024
Edited by proposal-police: This proposal was edited at 2024-08-28 16:13:58 UTC.
Proposal
Please re-state the problem that we are trying to solve in this issue.
Opening Two-Factor Authentication settings causes two duplicate API requests for EnableTwoFactorAuth
What is the root cause of that problem?
The behavior you're seeing, where not just the two-factor authentication call but all calls in useEffect are running twice, is due to React's Strict Mode. This change was introduced in this PR and is only in the development environment. We do not see this behavior in the production build.
What changes do you think we should make in order to solve the problem?
I prefer turning off Strict Mode, as introduced in this PR This way, development and production environments will behave the same.
We can disable strict mode from here
App/src/CONFIG.ts
Line 100 in cadd5a8
What alternative solutions did you explore? (Optional)
We can create a ref and then in useEffect we can early return if it's already mounted. With the implementation of useRef, we ensure that API calls within useEffect are made only once, even in development mode with React's Strict Mode enabled. This method prevents multiple invocations of the effect due to Strict Mode's behavior.
App/src/pages/settings/Security/TwoFactorAuth/Steps/CodesStep.tsx
Line 46 in a6564ac
We can do something like this
abzokhattab commentedon Aug 26, 2024
Not able to reproduce the issue on prod
tgolen commentedon Aug 28, 2024
Thanks for the investigation @Nodebrute. I think the thing that I really dislike about that is now dev is a very different environment than production, which makes testing and development much more difficult. We are being forced into some weird patterns (using a bunch of
useRef) to try and get development to work more like we expect production to work.Do you know if React is planning to make production work in this concurrent mode like dev is running in? I guess that would return it to an apples-to-apples situation at some point, which is better, but I really don't like having to guess "does this only happen in dev or not".
I'm going to assign this to external and get a C+ to review your proposal to implement (because even though it only happens in dev, it messed me up enough that I think it's worth fixing).
[-]Opening Two-Factor Authentication settings causes two duplicate API requests for EnableTwoFactorAuth[/-][+][$250] Opening Two-Factor Authentication settings causes two duplicate API requests for EnableTwoFactorAuth[/+]melvin-bot commentedon Aug 28, 2024
Job added to Upwork: https://www.upwork.com/jobs/~0184daf84295192016
23 remaining items
[-][$250] Opening Two-Factor Authentication settings causes two duplicate API requests for EnableTwoFactorAuth[/-][+][HOLD for payment][$250] Opening Two-Factor Authentication settings causes two duplicate API requests for EnableTwoFactorAuth[/+][-][HOLD for payment][$250] Opening Two-Factor Authentication settings causes two duplicate API requests for EnableTwoFactorAuth[/-][+][HOLD for payment - waiting on deploy][$250] Opening Two-Factor Authentication settings causes two duplicate API requests for EnableTwoFactorAuth[/+]johncschuster commentedon Sep 16, 2024
Waiting on QA to test the fix. @tgolen, it looks like Applause is asking on the PR which URL should be used for staging. Can you let them know?
mollfpr commentedon Sep 16, 2024
I have replied to the question.
johncschuster commentedon Sep 18, 2024
@mollfpr / @tgolen, I'm reviewing the linked PR to calculate the payment date, but I'm having trouble finding what I'm looking for. On #48722, I see it approved and merged but not deployed. I see our internal SO articles refer to using the merge date to calculate the regression threshold window, but without a deploy, I don't think we can really test for regressions. Can you help me sort out the date so I don't hold this one up?
mollfpr commentedon Sep 19, 2024
@johncschuster I think we can use the date for this issue #48791 closed. It's 11th September.
johncschuster commentedon Sep 20, 2024
Payment Summary:
Contributor: @Nodebrute paid $250 via Upwork - PAID
Contributor+: @mollfpr due $250 via NewDot
Upwork job here!
Please apply@mollfpr can you please provide regression test steps if they are necessary?
mollfpr commentedon Sep 22, 2024
@johncschuster I think we don't need a regression step since it's only affecting the development side and it's knowingly a feature from React but we happen not to need it yet.
johncschuster commentedon Sep 23, 2024
Ok great! Thanks for clarifying that! Please request payment via NewDot!
garrettmknight commentedon Sep 24, 2024
$250 approved for @mollfpr