Hacktoberfest 2026:维护者为十月标记出来的 issue,仍然开放、适合新手。 浏览 Hacktoberfest issue

`beforeAuthStateChanged` imported from `@angular/fire/auth` makes `ng build` fail during route extraction

未关闭
#3,748 0 条评论 0 个 reaction 已指派 0 人 在 GitHub 查看

还没有人认领这个 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 内容生成。

描述

comp: auth comp: ssr comp: zones type: bug
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
  1. Fresh ng new --ssr Angular 21 app, ng add @angular/fire@next.
  2. In app.config.ts, register beforeAuthStateChanged inside provideAppInitializer, 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).
  3. ng build fails with the error above (34 seconds in my run).
  4. 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 天 6 小时
30 天内合并 PR
5

贡献指南

打开贡献指南

从这里开始

  1. 先读完整个 Issue,再读项目的贡献指南。
  2. 在 Issue 下留言说明你要接手 —— 这能避免两个人做同样的事。
  3. Fork 仓库,在一个分支上完成修改。
  4. 提交 Pull Request,并在描述里引用这个 Issue 编号。

angular/angularfire 的其他 Issue

查看 angular/angularfire 的全部 Issue

相似的 Issue

更多 TypeScript Issue

把新 issue 发到你的邮箱

精选适合新手参与的 GitHub issue 摘要。