Skip to content

fix(auth): stale one-off AuthState no longer leaks across screen instances - #2415

Open
demolaf wants to merge 1 commit into
version-10.0.0-beta04from
fix/auth-state-stale-notification-reset
Open

fix(auth): stale one-off AuthState no longer leaks across screen instances#2415
demolaf wants to merge 1 commit into
version-10.0.0-beta04from
fix/auth-state-stale-notification-reset

Conversation

@demolaf

@demolaf demolaf commented Jul 23, 2026

Copy link
Copy Markdown
Member

A one-off AuthState (Error, Cancelled, SMSAutoVerified, PasswordResetLinkSent, EmailSignInLinkSent) written to FirebaseAuthUI's singleton state flow was never reset back to Idle after being consumed, so it got redelivered to a completely new screen/Activity that had nothing to do with the original event — reproduced by triggering a phone-auth error, backing out of the Activity, and re-entering: a stale "Authentication Error" dialog appeared immediately, before touching anything.

FirebaseAuthScreen, EmailAuthScreen, and PhoneAuthScreen now reset auth state back to Idle immediately after consuming Error/Cancelled/SMSAutoVerified in the same effect that reacts to them. TopLevelDialogController no longer keys its remember on the live auth state (or on an unmemoized stringProvider), since either caused the controller — and the dialog it was showing — to be torn down on the very next recomposition.

  • EmailAuthScreen.kt: resetLinkSent/emailSignInLinkSent are now latched into local state instead of derived directly from authState, since their confirmation dialogs latch on the boolean's transition and would otherwise close immediately when the reset above fires.

Added regression coverage in FirebaseAuthUIAuthStateTest and a new TopLevelDialogControllerTest proving stale state doesn't leak to a fresh collector and the dialog survives auth state changes.

Behavior

  • Before
bug-demo.webm
  • After
fix-dialog.webm

@gemini-code-assist gemini-code-assist Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

Code Review

This pull request refactors TopLevelDialogController to accept a lambda for retrieving the current AuthState, preventing the controller from being recreated on every state change. It also updates the auth screens to reset the auth state to Idle after consumption and introduces local state variables in EmailAuthScreen to manage UI states. Additionally, new unit tests are added to verify state consumption and controller survival. The review feedback highlights a potential race condition in the error dialog deduplication logic due to immediate state resetting, suggests keying the controller's remember block on stringProvider to prevent stale references, and recommends wrapping stringProvider in a remember block in FirebaseAuthScreen to avoid unnecessary recompositions.

Comment thread auth/src/main/java/com/firebase/ui/auth/ui/components/TopLevelDialogController.kt Outdated
Comment thread auth/src/main/java/com/firebase/ui/auth/ui/components/TopLevelDialogController.kt Outdated
@demolaf
demolaf marked this pull request as ready for review July 28, 2026 15:15
@demolaf
demolaf force-pushed the fix/auth-state-stale-notification-reset branch from fb5b700 to 267731e Compare July 28, 2026 15:19
@demolaf
demolaf force-pushed the fix/auth-state-stale-notification-reset branch from 267731e to e035a60 Compare July 29, 2026 00:45
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