Skip to content

refactor(auth): scope phone verification loading state to the composition that owns it - #2454

Merged
demolaf merged 2 commits into
version-10.0.0-beta05from
fix/phone-auth-loading-state-ownership
Aug 28, 2026
Merged

refactor(auth): scope phone verification loading state to the composition that owns it#2454
demolaf merged 2 commits into
version-10.0.0-beta05from
fix/phone-auth-loading-state-ownership

Conversation

@demolaf

@demolaf demolaf commented Aug 25, 2026

Copy link
Copy Markdown
Member

FirebaseAuthUI carried a revision counter plus clearLoadingState and currentAuthStateRevision purely so verifyPhoneNumber could retract its own AuthState.Loading on cancellation without clobbering whatever superseded it.

verifyPhoneNumber now writes no state on cancellation and just rethrows, and PhoneAuthScreen retracts its own Loading instead — in onChangeNumberClick, and from a DisposableEffect when the composition goes away mid-verification. Cancelling an attempt was already the screen's own bookkeeping, so the state it leaves behind belongs to the screen too.

Dropped three tests covering the removed API and the old callee-retracts contract, and added one to PhoneAuthScreenVerificationLifecycleTest for the change-number case — verified it fails without the change.

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

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.

Code Review

This pull request simplifies state management in FirebaseAuthUI by removing the AtomicLong revision tracking and instead handling the retraction of the Loading state directly within the UI layer using Compose's lifecycle. Specifically, a DisposableEffect is introduced in PhoneAuthScreen to reset the authentication state to Idle upon disposal if it was left in a Loading state. The review feedback points out a potential bug where rememberUpdatedState(authState) combined with DisposableEffect(authUI) can cause a mismatched state capture when authUI changes, as well as a race condition with cancellation. A code suggestion is provided to track the state per authUI instance using remember(authUI) { mutableStateOf(authState) }.

Comment thread auth/src/main/java/com/firebase/ui/auth/ui/screens/phone/PhoneAuthScreen.kt Outdated
@demolaf
demolaf marked this pull request as ready for review August 25, 2026 09:09
@demolaf
demolaf marked this pull request as draft August 25, 2026 14:10
@demolaf
demolaf changed the base branch from version-10.0.0-beta04 to version-10.0.0-beta05 August 26, 2026 14:32
@demolaf
demolaf marked this pull request as ready for review August 26, 2026 14:33
@demolaf
demolaf force-pushed the fix/phone-auth-loading-state-ownership branch from 485c2d9 to 3edb410 Compare August 26, 2026 16:30

@russellwheatley russellwheatley left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

LGTM. The core simplification is sound, traced through all the cancellation call sites and the DisposableEffect(authUI) cleanup correctly fixes the per-instance state capture bug flagged in review.

One thing worth a follow-up look: submitVerificationCode and signInWithPhoneAuthCredential still write AuthState.Error on CancellationException, so the same stale-state-after-disposal issue this PR fixes for verifyPhoneNumber might still apply if the screen disposes mid-flight on those. Pre-existing and out of scope here, not blocking.

@demolaf
demolaf force-pushed the fix/phone-auth-loading-state-ownership branch from 3edb410 to 98d196c Compare August 28, 2026 14:29
@demolaf
demolaf merged commit 65149e2 into version-10.0.0-beta05 Aug 28, 2026
9 checks passed
@github-project-automation github-project-automation Bot moved this from Backlog to Done in studio-2394994192-60a69 Aug 28, 2026
@demolaf
demolaf deleted the fix/phone-auth-loading-state-ownership branch August 28, 2026 14:36
@demolaf demolaf mentioned this pull request Aug 28, 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.

2 participants