Hacktoberfest 2026:メンテナが10月に向けて印を付けた、オープンで初心者向けの issue。 Hacktoberfest の issue を見る

[firebase_auth_web]: authStateChanges() never emits in --profile web builds (listener key 'no-op' collides)

クローズ
#18,728 コメント 0 件 リアクション 0 件 担当者 0 名 GitHub で見る

メンテナーはふだん 1 日以内に返信

まだ誰も着手していません。

評価

難易度
3/5
見積もり時間
1〜2日
初心者へのやさしさ
72/100
issue の種類
バグ
明瞭さ
明確に書かれている
活発さ
活発
技術スタック
dart

調査の方向性

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.

索引モデルが issue の本文から書いたものです。

説明

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_web builds the hot-restart listener key only under Flutter's kDebugMode. kDebugMode is false in 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_web stores and cancels those listeners under its own flag, which is true in profile:
    packages/firebase_core/firebase_core_web/lib/src/interop/utils/utils.dart:
    const bool _kDebugMode = !bool.fromEnvironment('dart.vm.product');
    
    setWindowsListener / unsubscribeWindowsListener / removeWindowsListener are 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
  1. Take any web app that listens to FirebaseAuth.instance.authStateChanges() and also triggers a second auth stream (idTokenChanges(), userChanges(), or a second authStateChanges() call).
  2. flutter build web --profile and serve build/web.
  3. Open it signed out. The authStateChanges() listener never fires. With flutter run -d chrome or flutter build web --release, it fires null straight 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.

主要言語
Dart
スター
9.3k
フォーク
4.1k
平均マージ
2日 2時間
マージ済み PR(30日)
34

環境構築

はじめの一歩

  1. issue を最後まで読み、次にプロジェクトのコントリビューションガイドを読みます。
  2. 着手することを issue にコメントします — 二人が同じ作業をするのを防げます。
  3. リポジトリをフォークし、ブランチを切って変更します。
  4. issue 番号を参照したプルリクエストを送ります。

firebase/flutterfire のほかの issue

firebase/flutterfire の issue をすべて見る

似ている issue

Dart の issue をもっと見る

新しい issue をメールで受け取る

初心者向けの GitHub issue を短くまとめたダイジェスト。