`beforeAuthStateChanged` imported from `@angular/fire/auth` makes `ng build` fail during route extraction
Nadie ha tomado este issue todavía.
Evaluación
- Dificultad
- 3/5
- Tiempo estimado
- 1-2 días
- Aptitud para principiantes
- 76/100
- Tipo de issue
- Error
- Claridad
- Bien especificado
- Estado de actividad
- Activo
- Stack tecnológico
- angular, typescript
- Área
- authentication, build-system
Línea de trabajo
Reproduce el fallo de extracción de rutas SSR con la configuración de la app descrita y, a continuación, inspecciona la línea 61 de src/auth/firebase.ts y el comportamiento de las tareas pendientes en src/zones.ts. Compara los wrappers relacionados en src/messaging/firebase.ts y src/app/firebase.ts, y verifica que registrar el hook de auth ya no impide que ng build finalice.
Escrito por el modelo de indexación a partir del texto del issue.
Descripción
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.
- Lenguaje dominante
- TypeScript
- Estrellas
- 7.8k
- Forks
- 2.2k
- Merge medio
- 3 d 6 h
- PR fusionados (30 d)
- 5
Guía de contribución
Primeros pasos
- Lee el issue completo y luego la guía de contribución del proyecto.
- Comenta en el issue que vas a ocuparte — evita que dos personas hagan lo mismo.
- Haz un fork del repositorio y trabaja en una rama.
- Abre un pull request que haga referencia al número del issue.
Más de angular/angularfire
-
comp: build/pipeline type: bug version: current (v17+)
Dificultad 2/5 1-3 horas Aptitud para principiantes 74/100
angular/angularfire#3766 ·
-
comp: schematics type: bug version: current (v17+)
Dificultad 3/5 1-2 días Aptitud para principiantes 76/100
angular/angularfire#3768 ·
-
comp: docs type: chore version: current (v17+)
Dificultad 4/5 3-5 días Aptitud para principiantes 58/100
angular/angularfire#3764 ·
-
comp: firestore comp: ssr priority: P0 (critical) type: feature version: current (v17+)
angular/angularfire#3757 · 1 asignado ·
-
Six `firebase` entry points have no `@angular/fire` equivalent, so their exports are unreachable Abiertocomp: core type: feature
angular/angularfire#3755 · 1 asignado ·
Todos los issues de angular/angularfire
Issues similares
-
[Bug]: Discord Activity titles with emoji are rejected as over 80 characters when they are not Abiertoclawsweeper:linked-pr-open clawsweeper:no-new-fix-pr clawsweeper:source-repro impact:message-loss issue-rating: 🦞 diamond lobster maturity:stable P2
Dificultad 2/5 1-3 horas Aptitud para principiantes 88/100
-
Dificultad 2/5 1-3 horas Aptitud para principiantes 84/100
Eynzof/Hermes-CN-Desktop#616 ·
-
ZCode 3.14.3 に対応する Abierto
Dificultad 2/5 1-3 horas Aptitud para principiantes 68/100
supermomonga/zcode-acp#24 ·
-
Dificultad 2/5 1-3 horas Aptitud para principiantes 76/100
growthbook/growthbook#7100 ·
-
triage
Dificultad 1/5 1-3 horas Aptitud para principiantes 88/100