`beforeAuthStateChanged` imported from `@angular/fire/auth` makes `ng build` fail during route extraction
Nobody has claimed this yet.
Assessment
- Difficulty
- 3/5
- Estimated time
- 1-2 days
- Newbie friendliness
- 76/100
- Issue type
- Bug
- Clarity
- Clearly specified
- Activity status
- Active
- Tech stack
- angular, typescript
- Domain
- authentication, build-system
Research direction
Reproduce the SSR route-extraction failure with the app configuration described, then inspect src/auth/firebase.ts line 61 and the pending-task behavior in src/zones.ts. Compare the related wrappers in src/messaging/firebase.ts and src/app/firebase.ts, and verify that registering the auth hook no longer prevents ng build from completing.
Written by the indexing model from the issue text.
Description
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.
- Dominant language
- TypeScript
- Stars
- 7.8k
- Forks
- 2.2k
- Avg merge
- 3d 6h
- Merged PRs (30d)
- 5
Contributor guide
First steps
- Read the whole issue, then the project's contributing guide.
- Comment on the issue to say you are picking it up — it saves two people doing the same work.
- Fork the repository and make your change on a branch.
- Open a pull request that references the issue number.
More from angular/angularfire
-
comp: build/pipeline type: bug version: current (v17+)
Difficulty 2/5 1-3 hours Newbie friendliness 74/100
angular/angularfire#3766 ·
-
comp: schematics type: bug version: current (v17+)
Difficulty 3/5 1-2 days Newbie friendliness 76/100
angular/angularfire#3768 ·
-
comp: docs type: chore version: current (v17+)
Difficulty 4/5 3-5 days Newbie friendliness 58/100
angular/angularfire#3764 ·
-
comp: firestore comp: ssr priority: P0 (critical) type: feature version: current (v17+)
angular/angularfire#3757 · 1 assignee ·
-
Six `firebase` entry points have no `@angular/fire` equivalent, so their exports are unreachable Opencomp: core type: feature
angular/angularfire#3755 · 1 assignee ·
All issues in angular/angularfire
Similar issues
-
Difficulty 2/5 1-3 hours Newbie friendliness 75/100
safetrustcr/dApp-SafeTrust#426 ·
-
area:workflow bug ready-for-agent
Difficulty 2/5 1-3 hours Newbie friendliness 75/100
fil-donadoni/tolaria#4409 ·
-
Difficulty 2/5 1-3 hours Newbie friendliness 70/100
Fission-AI/OpenSpec#1960 ·
-
Add dependabot Open
Difficulty 2/5 1-3 hours Newbie friendliness 70/100
-
Difficulty 2/5 1-3 hours Newbie friendliness 75/100
corsairdev/corsair#1764 ·