Title: `beforeAuthStateChanged` imported from `@angular/fire/auth` makes `ng build` fail during route extraction · Issue #3748 · angular/angularfire · GitHub
Open Graph Title: `beforeAuthStateChanged` imported from `@angular/fire/auth` makes `ng build` fail during route extraction · Issue #3748 · angular/angularfire
X Title: `beforeAuthStateChanged` imported from `@angular/fire/auth` makes `ng build` fail during route extraction · Issue #3748 · angular/angularfire
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 on...
Open Graph 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 ...
X 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 ...
Opengraph URL: https://github.com/angular/angularfire/issues/3748
X: @github
Domain: github.com
IPv4 address: 140.82.114.4
{"@context":"https://schema.org","@type":"DiscussionForumPosting","headline":"`beforeAuthStateChanged` imported from `@angular/fire/auth` makes `ng build` fail during route extraction","articleBody":"### Description\n\n`@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.\n\n`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:\n\n```\nAbortError: Routes extraction was aborted.\nTimeoutError: The operation was aborted due to timeout\n```\n\n### Steps to reproduce\n\n1. Fresh `ng new --ssr` Angular 21 app, `ng add @angular/fire@next`.\n2. 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).\n3. `ng build` fails with the error above (34 seconds in my run).\n4. Change only the import to `firebase/auth`. The identical code builds in under 5 seconds.\n\n### Expected behavior\n\nRegistering 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.\n\n### Workarounds in the wild\n\nOur 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.\n\n### Versions\n\nReproduced on an Angular 21 app against the @angular/fire 21 canary. The wrapper is unchanged on current `main`.\n","author":{"url":"https://github.com/armando-navarro","@type":"Person","name":"armando-navarro"},"datePublished":"2026-08-17T22:02:35Z","url":"https://github.com/angular/angularfire/issues/3748"}
| react-profiling | 0 |
| react-import-map | react,react-dom,react-dom/client,react-dom/profiling,react-is,react/compiler-runtime,react/jsx-dev-runtime,react/jsx-runtime,scheduler@b8488ee2c322 |
| route-pattern | /_view_fragments/issues/show/:user_id/:repository/:id/issue_layout(.:format) |
| route-controller | voltron_issues_fragments |
| route-action | issue_layout |
| fetch-nonce | v2:0fd06304-95a8-c7a6-25f5-093717416898 |
| current-catalog-service-hash | 81bb79d38c15960b92d99bca9288a9108c7a47b18f2423d0f6438c5b7bcd2114 |
| request-id | BAD6:1F320A:8CF05A:B1CD3C:6B035FFC |
| html-safe-nonce | 82851975e1873708b07fa09c9a3a43229f6428a952966093a335bd359d42cc80 |
| visitor-payload | eyJyZWZlcnJlciI6IiIsInJlcXVlc3RfaWQiOiJCQUQ2OjFGMzIwQTo4Q0YwNUE6QjFDRDNDOjZCMDM1RkZDIiwidmlzaXRvcl9pZCI6IjYwNjcyNDY5OTY1NjgzNjcxMDAiLCJyZWdpb25fZWRnZSI6ImlhZCIsInJlZ2lvbl9yZW5kZXIiOiJpYWQifQ== |
| visitor-hmac | c6cfaf715b2ec75c0bbef98527b2d4170547c4edb1e4ed673db3aaa41ca0d4cc |
| hovercard-subject-tag | issue:5175836677 |
| github-keyboard-shortcuts | repository,issues,copilot |
| google-site-verification | Apib7-x98H0j5cPqHWwSMm6dNU4GmODRoqxLiDzdx9I |
| octolytics-url | https://collector.github.com/github/collect |
| analytics-location | / |
| fb:app_id | 1401488693436528 |
| apple-itunes-app | app-id=1477376905, app-argument=https://github.com/_view_fragments/issues/show/angular/angularfire/3748/issue_layout |
| twitter:image | https://opengraph.githubassets.com/2d61f3a846d0f059e2fc5a48c53fef396ad167168616badcbb6d8df592db46f5/angular/angularfire/issues/3748 |
| twitter:card | summary_large_image |
| og:image | https://opengraph.githubassets.com/2d61f3a846d0f059e2fc5a48c53fef396ad167168616badcbb6d8df592db46f5/angular/angularfire/issues/3748 |
| og:image:alt | 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 ... |
| og:image:width | 1200 |
| og:image:height | 600 |
| og:site_name | GitHub |
| og:type | object |
| og:author:username | armando-navarro |
| hostname | github.com |
| expected-hostname | github.com |
| None | 87e774ee7c6b3bee0490394e4d3e57ec9dbc956f74b87ea685dc8996c1676456 |
| turbo-cache-control | no-preview |
| go-import | github.com/angular/angularfire git https://github.com/angular/angularfire.git |
| octolytics-dimension-user_id | 139426 |
| octolytics-dimension-user_login | angular |
| octolytics-dimension-repository_id | 49453413 |
| octolytics-dimension-repository_nwo | angular/angularfire |
| octolytics-dimension-repository_public | true |
| octolytics-dimension-repository_is_fork | false |
| octolytics-dimension-repository_network_root_id | 49453413 |
| octolytics-dimension-repository_network_root_nwo | angular/angularfire |
| turbo-body-classes | logged-out env-production page-responsive |
| disable-turbo | false |
| browser-stats-url | https://api.github.com/_private/browser/stats |
| browser-errors-url | https://api.github.com/_private/browser/errors |
| release | 423dbb54c5e7bfecc838eb387c1435eb3d0e760d |
| ui-target | full |
| theme-color | #1e2327 |
| color-scheme | light dark |
| react-app-name | issues |
Links:
| Server | github.com |
| Content-Type | text/html; charset=utf-8 |
| Cache-Control | max-age=0, private, must-revalidate |
Viewport: width=device-width