[firebase_auth_web]: authStateChanges() never emits in --profile web builds (listener key 'no-op' collides)
Los mantenedores suelen responder en 1 día
Nadie ha tomado este issue todavía.
Evaluación
- Dificultad
- 3/5
- Tiempo estimado
- 1-2 días
- Aptitud para principiantes
- 72/100
- Tipo de issue
- Error
- Claridad
- Bien especificado
- Estado de actividad
- Activo
- Stack tecnológico
- dart
- Área
- authentication, web-dev
Línea de trabajo
Start with packages/firebase_auth/firebase_auth_web/lib/src/interop/auth.dart and packages/firebase_core/firebase_core_web/lib/src/interop/utils/utils.dart, focusing on _authStateWindowsKey(), _idTokenStateWindowsKey(), and the listener storage methods. Reproduce with a Flutter web app using flutter build web --profile and multiple auth streams. Done means authStateChanges() emits its initial state in profile builds without cancelling another listener, while debug and release behavior remains intact.
Escrito por el modelo de indexación a partir del texto del issue.
Descripción
Is there an existing issue for this?
- I have searched the existing issues.
Which plugins are affected?
Auth, Core
Which platforms are affected?
Web
Description
In a flutter build web --profile build, FirebaseAuth.instance.authStateChanges() never emits. An app that waits for the first auth event (for example a router redirect that holds a splash screen until auth state is known) hangs forever. Debug and release builds work.
The JS SDK itself is fine. In the same page, onAuthStateChanged called directly through the JS SDK fires immediately with null.
Cause. The two packages disagree about what "debug" means:
firebase_auth_webbuilds the hot-restart listener key only under Flutter'skDebugMode.kDebugModeisfalsein profile, so every listener gets the same key,'no-op':
packages/firebase_auth/firebase_auth_web/lib/src/interop/auth.dart,_authStateWindowsKey()/_idTokenStateWindowsKey():if (kDebugMode) { ... return '$key-${_authStateListeners[key]}'; } return 'no-op';firebase_core_webstores and cancels those listeners under its own flag, which istruein profile:
packages/firebase_core/firebase_core_web/lib/src/interop/utils/utils.dart:const bool _kDebugMode = !bool.fromEnvironment('dart.vm.product');setWindowsListener/unsubscribeWindowsListener/removeWindowsListenerare all gated on it.
So in profile, onAuthStateChanged / onIdTokenChanged store their JS unsubscribe function at window['no-op']. The next getter call runs unsubscribeWindowsListener('no-op'), which calls that stored function and cancels the previous subscription's JS listener. The Dart StreamController stays open but never receives an event. The event it seeded with _changeController!.add(_initUser) was added before any listener existed, so the broadcast controller dropped it.
In release both flags are false, and in debug both are true with unique keys, which is why only profile is affected.
The code is unchanged on main as of today.
Suggested fix: use the same condition in both places. For example, have firebase_core_web use kDebugMode from package:flutter/foundation.dart, or make _authStateWindowsKey() / _idTokenStateWindowsKey() always return a unique key.
Reproducing the issue
- Take any web app that listens to
FirebaseAuth.instance.authStateChanges()and also triggers a second auth stream (idTokenChanges(),userChanges(), or a secondauthStateChanges()call). flutter build web --profileand servebuild/web.- Open it signed out. The
authStateChanges()listener never fires. Withflutter run -d chromeorflutter build web --release, it firesnullstraight away.
To confirm it is the listener being cancelled, put prints in the stream: the provider builds and the redirect runs with the state still loading, but no event ever arrives. In the same page, firebase_auth.onAuthStateChanged(getAuth(app), cb) from the JS SDK fires at once.
Firebase Core version
4.15.0 (firebase_core_web 3.12.0)
Flutter Version
3.47.2
Relevant Log Output
No error is logged. The auth stream is silently cancelled.
Flutter dependencies
firebase_core: 4.15.0
firebase_core_web: 3.12.0
firebase_auth: 6.7.0
firebase_auth_web: 6.3.0
Additional context and comments
Found while profiling a production app. The fix above is based on reading the source, and the diagnosis was confirmed with print statements in a profile build. I have not built a standalone minimal repro project.
- Lenguaje dominante
- Dart
- Estrellas
- 9.3k
- Forks
- 4.1k
- Merge medio
- 1 d 14 h
- PR fusionados (30 d)
- 39
Preparar el entorno
- Sin Dockerfile ni archivo de Docker Compose
- Tiene una plantilla de pull request
- Leer la guía de contribución
Primeros pasos
- Lee el issue completo y luego la guía de contribución del proyecto.
- Comenta en el issue que vas a ocuparte — evita que dos personas hagan lo mismo.
- Haz un fork del repositorio y trabaja en una rama.
- Abre un pull request que haga referencia al número del issue.
Más de firebase/flutterfire
-
Needs Attention platform: windows plugin: cloud_firestore reproduced type: bug
Dificultad 2/5 1-3 horas Aptitud para principiantes 84/100
firebase/flutterfire#18735 · 1 comentario ·
Los mantenedores suelen responder en 1 día
-
[cloud_firestore]: a snapshots() listener cancelled while it registers is never removed nativelyAbiertoNeeds Attention platform: android platform: ios platform: macos plugin: cloud_firestore reproduced type: bug
Dificultad 3/5 1-2 días Aptitud para principiantes 72/100
firebase/flutterfire#18724 · 1 comentario ·
Los mantenedores suelen responder en 1 día
-
blocked: customer-response platform: web plugin: cloud_firestore Stale type: bug
Dificultad 4/5 3-5 días Aptitud para principiantes 48/100
firebase/flutterfire#18700 · 3 comentarios ·
Los mantenedores suelen responder en 1 día
-
Needs Attention platform: ios plugin: messaging reproduced type: bug
Dificultad 3/5 1-2 días Aptitud para principiantes 74/100
firebase/flutterfire#18699 · 4 comentarios · 1 reacción ·
Los mantenedores suelen responder en 1 día
-
blocked: flutter platform: windows plugin: storage reproduced type: bug
Dificultad 5/5 Más de una semana Aptitud para principiantes 25/100
firebase/flutterfire#18664 · 3 comentarios ·
Los mantenedores suelen responder en 1 día
Todos los issues de firebase/flutterfire
Issues similares
-
Dificultad 1/5 Menos de una hora Aptitud para principiantes 90/100
Los mantenedores suelen responder en 1 día
-
Dificultad 2/5 1-3 horas Aptitud para principiantes 85/100
immich-app/immich#31955 ·
Los mantenedores suelen responder en 1 día
-
bug triage
Dificultad 2/5 1-3 horas Aptitud para principiantes 82/100
fluttercommunity/plus_plugins#3994 ·
Los mantenedores suelen responder en 1 día
-
[BUG] iOS: a feature drag interrupted by the system never ends, and the next pan drags the featureAbierto
Dificultad 2/5 1-3 horas Aptitud para principiantes 84/100
maplibre/flutter-maplibre-gl#1053 ·
Los mantenedores suelen responder en 1 día
-
Dificultad 2/5 1-3 horas Aptitud para principiantes 72/100