`beforeAuthStateChanged` imported from `@angular/fire/auth` makes `ng build` fail during route extraction
維護者通常 3 天內回覆
還沒有人認領這個 Issue。
評估
- 難度
- 3/5
- 預估耗時
- 1-2 天
- 新手友好度
- 76/100
- Issue 類型
- 缺陷
- 描述清晰度
- 描述清楚
- 活躍度
- 活躍
- 技術堆疊
- angular, typescript
研究方向
使用所述的應用程式設定重現 SSR 路由擷取失敗,然後檢查 src/auth/firebase.ts 第 61 行以及 src/zones.ts 中待處理任務的行為。比較 src/messaging/firebase.ts 和 src/app/firebase.ts 中相關的包裝器,並驗證註冊 auth hook 不再阻止 ng build 完成。
由索引模型根據 Issue 內容生成。
描述
Description
@angular/fire/auth wraps beforeAuthStateChanged as ɵzoneWrap(_beforeAuthStateChanged, true) (src/auth/firebase.ts line 61). With that flag, the wrapper registers a pending task as soon as a callback is passed and clears it only when the callback first fires or the returned unsubscribe runs (src/zones.ts). This callback only fires when a sign-in or sign-out happens, so an app that registers the hook at startup holds the pending task open and ApplicationRef.isStable never becomes true for a visitor who is not signing in or out.
ng build route extraction waits on app stability, so any server-rendered app that registers this hook in its app config cannot build. Extraction hangs for about 30 seconds, then:
AbortError: Routes extraction was aborted.
TimeoutError: The operation was aborted due to timeout
Steps to reproduce
- Fresh
ng new --ssrAngular 21 app,ng add @angular/fire@next. - In
app.config.ts, registerbeforeAuthStateChangedinsideprovideAppInitializer, imported from@angular/fire/auth. Registering it at startup is exactly what an SSR token-cookie sync does (docs/auth.md, Server-side Rendering section). ng buildfails with the error above (34 seconds in my run).- Change only the import to
firebase/auth. The identical code builds in under 5 seconds.
Expected behavior
Registering the hook does not permanently block app stability. onMessage in src/messaging/firebase.ts wraps the same shape of API, a callback that may never fire, with the flag set to false, which still zone-wraps the callback and only skips the pending task. The same flag here looks like the fix, pending a check that nothing relies on the blocking behavior. onLog in src/app/firebase.ts has the same shape and is worth sweeping at the same time.
Workarounds in the wild
Our own sample already imports beforeAuthStateChanged from firebase/auth (sample/src/app/auth/auth.component.ts), and the rewritten SSR docs section in #3740 documents that import as the way around this bug.
Versions
Reproduced on an Angular 21 app against the @angular/fire 21 canary. The wrapper is unchanged on current main.
- 主要語言
- TypeScript
- 星號
- 7.8k
- 分支
- 2.2k
- 平均合併
- 3 天 7 小時
- 30 天內合併 PR
- 8
環境準備
- 沒有 Dockerfile 或 Docker Compose 檔案
- 有 Pull Request 範本
- 閱讀貢獻指南
從這裡開始
- 先讀完整個 Issue,再讀專案的貢獻指南。
- 在 Issue 下留言說明你要接手 —— 這能避免兩個人做同樣的事。
- Fork 儲存庫,在一個分支上完成修改。
- 送出 Pull Request,並在描述裡引用這個 Issue 編號。
angular/angularfire 的其他 Issue
-
comp: other type: chore
難度 1/5 1 小時以內 新手友好度 90/100
angular/angularfire#3781 ·
維護者通常 3 天內回覆
-
comp: app-check comp: docs comp: ssr type: chore version: current (v17+)
難度 2/5 1-3 小時 新手友好度 88/100
angular/angularfire#3774 ·
維護者通常 3 天內回覆
-
comp: build/pipeline type: bug version: current (v17+)
難度 3/5 1-2 天 新手友好度 55/100
angular/angularfire#3779 ·
維護者通常 3 天內回覆
-
Use `TransferState` to hand server-rendered Firestore data to the browser, instead of reading every document twice可能重新可做 @armando-navarro 於 31 天前認領,目前沒有進行中的 PR。 未關閉comp: firestore comp: ssr priority: P0 (critical) type: feature version: current (v17+)
angular/angularfire#3757 · 已指派 1 人 ·
維護者通常 3 天內回覆
-
Six `firebase` entry points have no `@angular/fire` equivalent, so their exports are unreachable可能重新可做 @armando-navarro 於 32 天前認領,目前沒有進行中的 PR。 未關閉comp: core type: feature
angular/angularfire#3755 · 已指派 1 人 ·
維護者通常 3 天內回覆
查看 angular/angularfire 的全部 Issue
相似的 Issue
-
難度 1/5 1 小時以內 新手友好度 72/100
betagouv/mon-entreprise#4699 ·
維護者通常 3 天內回覆
-
bug
難度 2/5 1-3 小時 新手友好度 82/100
jaegertracing/jaeger-ui#4547 · 3 則留言 ·
維護者通常 1 天內回覆
-
ai-driven-qa
難度 2/5 1-3 小時 新手友好度 84/100
linagora/twake-calendar-frontend#1467 ·
維護者通常 1 天內回覆
-
難度 2/5 1-3 小時 新手友好度 78/100
need4deed-org/sdk#267 ·
維護者通常 1 天內回覆
-
難度 2/5 1-3 小時 新手友好度 84/100
auth0/universal-login#414 ·
維護者通常 1 天內回覆