Skip to content

fix(settings): defer AlertBar click-outside arming to next tick#20663

Closed
vpomerleau wants to merge 1 commit into
mainfrom
FXA-13681-part-2
Closed

fix(settings): defer AlertBar click-outside arming to next tick#20663
vpomerleau wants to merge 1 commit into
mainfrom
FXA-13681-part-2

Conversation

@vpomerleau
Copy link
Copy Markdown
Contributor

Because

  • The "Passkey setup was canceled. Try again." banner intermittently fails to appear on the first cancel after a fresh sign-in (QA repro on Stage 1.337.0), leaving the user without confirmation that their cancellation was processed.

This pull request

  • Replaces useClickOutsideEffect in AlertBar with an inline effect keyed on visible that arms the body-click listener one macrotask after visible flips to true, so the click that opened the alert cannot also close it.
  • Only attaches the body-level click listener while the alert is visible (small correctness improvement over the previous always-on listener).
  • Preserves the ESC-key close path and the existing modal-coexistence rule (FXA-2463 TODO) for clicks while a Settings Modal is open.
  • Adds index.race.test.tsx to exercise real reactive vars + fake timers, covering the same-click race, the subsequent-click close, the modal coexistence rule, and inside-the-alert clicks.

Issue that this pull request solves

Closes: FXA-13681

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).
  • I have manually reviewed all AI generated code.

How to review (Optional)

  • Key files/areas to focus on:
  • Suggested review order:
  • Risky or complex parts:

Screenshots (Optional)

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

Other information (Optional)

This is a follow-up to a previously merged fix for FXA-13681. The first attempt didn't catch the race because existing unit tests mocked `alertBarInfo` and never rendered the real `AlertBar`. The new `index.race.test.tsx` closes that coverage gap.

Because:

- The "Passkey setup was canceled. Try again." banner intermittently failed
to appear on the first cancel after a fresh sign-in (QA on Stage 1.337.0).
The Cancel-button click that calls alertBar.error() bubbles to <body> in
the same task as React commits the alert into the DOM; AlertBar's global
click-outside listener then sees the now-attached ref, treats the click as
"outside", and closes the alert before the user can see it. Existing unit
tests didn't catch this because they mock alertBarInfo and never render the
real AlertBar.

This commit:

- Replaces useClickOutsideEffect in AlertBar with an inline effect keyed on
visible that arms the body-click listener one macrotask after visible flips
to true, so the click that opened the alert cannot also close it.
- Only attaches the listener while the alert is visible (small correctness
improvement over the previous always-on body listener).
- Preserves the ESC-key close path and the existing modal-coexistence rule
(FXA-2463 TODO) for clicks while a Settings Modal is open.
- Adds index.race.test.tsx exercising real reactive vars + fake timers to
cover the same-click race, the subsequent-click close, the modal
coexistence rule, and inside-the-alert clicks.

Closes #FXA-13681
@vpomerleau
Copy link
Copy Markdown
Contributor Author

Continued investigating, this looks like the wrong solution.

@vpomerleau vpomerleau closed this May 29, 2026
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.

1 participant