Hacktoberfest 2026: le issue che i maintainer hanno segnato per ottobre, aperte e adatte ai principianti. Sfoglia le issue Hacktoberfest

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

Aperta
#3,748 0 commenti 0 reazioni 0 assegnatari Vedi su GitHub

Nessuno ha ancora preso questa issue.

Valutazione

Difficoltà
3/5
Tempo stimato
1-2 giorni
Idoneità per principianti
76/100
Tipo di issue
Bug
Chiarezza
Specificata chiaramente
Stato di attività
Attiva
Stack tecnologico
angular, typescript

Direzione di ricerca

Riproduci il fallimento dell’estrazione delle route SSR con la configurazione dell’app descritta, quindi esamina la riga 61 di src/auth/firebase.ts e il comportamento delle attività in sospeso in src/zones.ts. Confronta i wrapper correlati in src/messaging/firebase.ts e src/app/firebase.ts e verifica che la registrazione dell’hook di auth non impedisca più a ng build di completare l’esecuzione.

Scritto dal modello di indicizzazione a partire dal testo della issue.

Descrizione

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.

Lingua principale
TypeScript
Stelle
7.8k
Fork
2.2k
Merge medio
3g 6h
PR unite (30g)
5

Guida per i contributori

Apri la guida per i contributori

Come iniziare

  1. Leggi tutta la issue e poi la guida ai contributi del progetto.
  2. Commenta sulla issue per dire che te ne occupi tu — evita che due persone facciano lo stesso lavoro.
  3. Fai un fork del repository e lavora su un branch.
  4. Apri una pull request che faccia riferimento al numero della issue.

Altre issue di angular/angularfire

Tutte le issue di angular/angularfire

Issue simili

Altre issue su TypeScript

Ricevi le nuove issue nella tua casella

Un breve riepilogo di issue GitHub adatte ai principianti.