[firebase_core_web]: Firebase.initializeApp never completes when a Firebase JS SDK script fails to load
メンテナーはふだん 1 日以内に返信
評価
- 難易度
- 2/5
- 見積もり時間
- 1〜3時間
- 初心者へのやさしさ
- 62/100
- issue の種類
- バグ
- 明瞭さ
- 明確に書かれている
- 活発さ
- 活発
- 技術スタック
- dart, javascript
- 領域
- web-dev
調査の方向性
関連するコードは lib/src/firebase_core_web.dart の injectSrcScript です。このメソッドは ff_trigger_* ヘルパーを注入し、そのコールバックのみを待機するため、拒否された動的な import() があると completer が保留のまま残ります。まずこのメソッドと、注入される JS ヘルパーを読んでください。次に、存在しない URL を指定して injectSrcScript を呼び出し、タイムアウトするかどうかを確認して問題を再現してください。スクリプトの読み込みに失敗したときに、返される future がエラーで完了し、そのケースをテストが網羅していれば完了です。
索引モデルが issue の本文から書いたものです。
説明
Is there an existing issue for this?
- I have searched the existing issues.
Which plugins are affected?
Core
Which platforms are affected?
Web
Description
On web, Firebase.initializeApp() loads the Firebase JS SDK from www.gstatic.com with a dynamic import() per service (injectSrcScript in lib/src/firebase_core_web.dart). The injected helper looks like this:
window.ff_trigger_firebase_core = async (callback) => {
callback(await import("https://www.gstatic.com/firebasejs/<version>/firebase-app.js"));
};
and the Dart side only waits for the callback:
Completer completer = Completer();
globalContext.callMethod('ff_trigger_$windowVar'.toJS, (JSAny module) {
globalContext[windowVar] = module;
globalContext.delete('ff_trigger_$windowVar'.toJS);
completer.complete();
}.toJS);
await completer.future;
If the import() rejects (network drop, request blocked, CDN error), the callback is never called, so the completer never completes and Firebase.initializeApp() never returns. The rejection itself only shows up as an unhandled promise rejection (Safari: TypeError: Importing a module script failed., Chrome: TypeError: Failed to fetch dynamically imported module: ...).
For the user this is an app that never starts, with no error the app can catch, retry or show. We see this in production on iOS Safari (13 events in 8 months).
Expected: Firebase.initializeApp() fails with an error when one of the SDK scripts cannot be loaded, so the app can handle it (show an error, retry, reload).
Reproducing the issue
Call injectSrcScript (the method initializeApp uses) with a URL that cannot be loaded:
final coreWeb = FirebaseCoreWeb();
await coreWeb
.injectSrcScript('${web.window.location.origin}/does-not-exist.js', 'firebase_missing')
.timeout(const Duration(seconds: 10));
// TimeoutException: Future not completed
Or in an app: block www.gstatic.com in DevTools (Network request blocking) and call Firebase.initializeApp(). It never returns and runApp is never reached.
Firebase Core version
latest main (firebase_core_web)
Flutter Version
stable
Relevant Log Output
Unhandled Promise Rejection: TypeError: Importing a module script failed.
Flutter dependencies
n/a
Additional context and comments
The helper is already an async function, so it returns a promise that rejects when import() fails. Awaiting that promise instead of only the callback is enough to surface the error. I have a PR ready.
- 主要言語
- Dart
- スター
- 9.3k
- フォーク
- 4.1k
- 平均マージ
- 2日 10時間
- マージ済み PR(30日)
- 78
環境構築
- Dockerfile・Docker Compose ファイルなし
- プルリクエストのテンプレートあり
- コントリビューションガイドを読む
はじめの一歩
- issue を最後まで読み、次にプロジェクトのコントリビューションガイドを読みます。
- 着手することを issue にコメントします — 二人が同じ作業をするのを防げます。
- リポジトリをフォークし、ブランチを切って変更します。
- issue 番号を参照したプルリクエストを送ります。
firebase/flutterfire のほかの issue
-
🚀 [firebase_core] Bump Firebase C++ SDK (14.1.0 → 14.2.0)対応中かも @SelaseKay が今日担当しました。 オープンNeeds Attention type: enhancement
難易度 2/5 1〜3時間 初心者へのやさしさ 70/100
firebase/flutterfire#18977 · コメント 1 件 ·
メンテナーはふだん 1 日以内に返信
-
Needs Attention platform: android plugin: crashlytics type: enhancement
難易度 4/5 3〜5日 初心者へのやさしさ 48/100
firebase/flutterfire#18951 · コメント 2 件 ·
メンテナーはふだん 1 日以内に返信
-
blocked: external dependency platform: web plugin: ai type: bug
難易度 4/5 3〜5日 初心者へのやさしさ 48/100
firebase/flutterfire#18938 · コメント 2 件 ·
メンテナーはふだん 1 日以内に返信
-
[cloud_firestore][Windows] Invalid field names (empty or `__x__`) close the app instead of throwing a FirebaseException対応中かも @SelaseKay が 5 日前に担当しました。 オープンNeeds Attention platform: windows plugin: cloud_firestore reproduced type: bug type: crash
難易度 4/5 3〜5日 初心者へのやさしさ 52/100
firebase/flutterfire#18928 · コメント 1 件 ·
メンテナーはふだん 1 日以内に返信
-
Needs Attention plugin: ai type: enhancement
難易度 3/5 1〜2日 初心者へのやさしさ 67/100
firebase/flutterfire#18917 ·
メンテナーはふだん 1 日以内に返信
firebase/flutterfire の issue をすべて見る
似ている issue
-
documentation
難易度 2/5 1〜3時間 初心者へのやさしさ 82/100
-
難易度 2/5 1〜3時間 初心者へのやさしさ 67/100
-
agent: is checked on a wrapper holding several checkables answers from the first one in tree orderオープンbug
難易度 2/5 1〜3時間 初心者へのやさしさ 76/100
AlphaWaveSystems/flutter-probe#865 ·
メンテナーはふだん 1 日以内に返信
-
bug
難易度 2/5 1〜3時間 初心者へのやさしさ 65/100
ubuntu/app-center#2306 ·
メンテナーはふだん 1 日以内に返信
-
enhancement
難易度 2/5 1〜3時間 初心者へのやさしさ 64/100
spotiflacapp/SpotiFLAC-Mobile#923 ·