Skip to content

task(settings): Debounce sending of code on click and render#19442

Merged
dschom merged 1 commit intomainfrom
FXA-12390
Sep 15, 2025
Merged

task(settings): Debounce sending of code on click and render#19442
dschom merged 1 commit intomainfrom
FXA-12390

Conversation

@dschom
Copy link
Copy Markdown
Contributor

@dschom dschom commented Sep 11, 2025

Because

  • Due to mobile issue the previous debounce technique might still have issues

This pull request

  • Caches record of when MFA OTP code requests occur
  • Uses record to determine whether or not to debounce
  • Also handles case where some one hammers the 'resend' button

Issue that this pull request solves

Closes: FXA-12390

Checklist

Put an x in the boxes that apply

  • My commit is GPG signed.
  • If applicable, I have modified or added tests which pass locally.
  • I have added necessary documentation (if appropriate).
  • I have verified that my changes render correctly in RTL (if appropriate).

Screenshots (Optional)

Please attach the screenshots of the changes made in case of change in user interface.

Other information (Optional)

Any other information that is important to this pull request.

@dschom dschom requested a review from a team as a code owner September 11, 2025 22:28
@dschom dschom force-pushed the FXA-12390 branch 3 times, most recently from 0cc4527 to b1560c2 Compare September 12, 2025 01:08
Copy link
Copy Markdown
Contributor

@MagentaManifold MagentaManifold left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I manually tested and it works. Thanks Dan!

Copy link
Copy Markdown
Contributor

@vpomerleau vpomerleau left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks for the improvements. Tested locally and working well to prevent resend on reload. Just a few non-blocking comments.

);

await act(async () => {
await new Promise((r) => setTimeout(r, 101));
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Could we consider using Jest's useFakeTimers instead of setTimeout? It's a drop in the bucket, but likely better practice for runtime on CI.

Copy link
Copy Markdown
Contributor Author

@dschom dschom Sep 15, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think that's a good recommendation. I actually tried using useFakeTimers but it didn't work... but it wasn't apparent why. I can try again, but will land that in a polish PR.

* The main purpose of this cache is to track when we email users
* MFA OTP codes. This info can then be used to debounce sends.
*/
export class MfaOtpRequestCache {
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Observation: the cache for tokens and requests doesn't get cleared on account signout. Likely not a big deal since it can't be reused if the session token is no longer valid?

Copy link
Copy Markdown
Contributor Author

@dschom dschom Sep 15, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Excellent point. I'll clear these caches on sign out. I'll do this in a separate PR though.


const handleResendCode = async () => {
// Stop users from hammering the resend button...
if (debounce(debounceIntervalMs)) {
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The interval is currently pretty small, so it's not too much of a concern rn, but if we were to increase the wait time for resends we should provide clear feedback in the UI (disable the button or return an info/error message). This would be less confusing for the user.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I was also considering this. I was doing a little research on this and it seemed like if the interval was small it's alright to just debounce quietly.

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yeah, agree that with the current very short timeout it's not much of a problem.

});
});

it('debounces OPT resend requests', async () => {
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

typo

Suggested change
it('debounces OPT resend requests', async () => {
it('debounces OTP resend requests', async () => {

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks!

Because:
- Due to mobile issue the previous debounce technique might still have issues

This Commit:
- Caches record of when MFA OTP code requests occur
- Uses record to determine whether or not to debounce
- Also handles case where some one hammers the 'resend' button
@dschom dschom merged commit 608f3e2 into main Sep 15, 2025
19 checks passed
@dschom dschom deleted the FXA-12390 branch September 15, 2025 20:28
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants