Repository navigation
fix(auth): stop beforeAuthStateChanged from holding the app unstable - #3770
Conversation
AngularFire wrapped beforeAuthStateChanged so that registering the hook added a pending task, cleared only when the callback first runs. Firebase runs that callback only on a sign-in or sign-out, so for a visitor who does neither the app never became stable. Registered on the server, it failed ng build during route extraction and left server-rendered requests without a response. This restores the blockUntilFirst: false override from angular#3590, which angular#3613 dropped without comment while adding log-level overrides next to it. The callback still runs inside Angular's zone and injection context, and its returned promise still reaches Firebase, so a rejection still cancels the sign-in. A call outside an injection context now logs its per-call warning only at the verbose level, as onMessage does. Fixes angular#3748
tyler-reitz
left a comment
There was a problem hiding this comment.
Approving.
Rebuilt from the generator and confirmed src/auth/firebase.ts matches its output, with a control run flipping the override to prove that check can fail. The #3590 / #3613 history is exactly as you describe.
Two follow-ups, neither blocking:
The beforeAuthStateChanged from firebase/auth section of docs/auth.md describes the blocking behavior in the present tense and points at #3748 as open. Merging this closes #3748, so that section wants a version qualifier like the one in #3769's docs, or a follow-up issue to point at.
This override has now been added, dropped and re-added with no test. A spec in src/auth/auth.spec.ts asserting the app becomes stable after registering the hook would have gone red on #3613.
Merging this change closes angular#3748, so the section's present-tense note would point at a closed issue. Also removed the false claim that the @angular/fire/auth import makes ng build hang: the guide registers the hook only in the browser, so its own build succeeds.
|
Thanks Tyler.
|
…ngular#3770) AngularFire wrapped beforeAuthStateChanged so that registering the hook added a pending task, cleared only when the callback first runs. Firebase runs that callback only on a sign-in or sign-out, so for a visitor who does neither the app never became stable. Registered on the server, it failed ng build during route extraction and left server-rendered requests without a response. This restores the blockUntilFirst: false override from angular#3590, which angular#3613 dropped without comment while adding log-level overrides next to it. The callback still runs inside Angular's zone and injection context, and its returned promise still reaches Firebase, so a rejection still cancels the sign-in. A call outside an injection context now logs its per-call warning only at the verbose level, as onMessage does. Fixes angular#3748 docs(auth): scope the beforeAuthStateChanged note to rc.1 and earlier Merging this change closes angular#3748, so the section's present-tense note would point at a closed issue. Also removed the false claim that the @angular/fire/auth import makes ng build hang: the guide registers the hook only in the browser, so its own build succeeds. The docs/auth.md change is left out, since it edits a section of the guide that 20.1.x does not have. (cherry picked from commit f182972)
…3770) AngularFire wrapped beforeAuthStateChanged so that registering the hook added a pending task, cleared only when the callback first runs. Firebase runs that callback only on a sign-in or sign-out, so for a visitor who does neither the app never became stable. Registered on the server, it failed ng build during route extraction and left server-rendered requests without a response. This restores the blockUntilFirst: false override from #3590, which #3613 dropped without comment while adding log-level overrides next to it. The callback still runs inside Angular's zone and injection context, and its returned promise still reaches Firebase, so a rejection still cancels the sign-in. A call outside an injection context now logs its per-call warning only at the verbose level, as onMessage does. Fixes #3748 docs(auth): scope the beforeAuthStateChanged note to rc.1 and earlier Merging this change closes #3748, so the section's present-tense note would point at a closed issue. Also removed the false claim that the @angular/fire/auth import makes ng build hang: the guide registers the hook only in the browser, so its own build succeeds. The docs/auth.md change is left out, since it edits a section of the guide that 20.1.x does not have. (cherry picked from commit f182972)
…te (#3817) The auth guide's cookie sync and the sample app imported beforeAuthStateChanged from firebase/auth, because AngularFire's version kept the app unstable until the first sign-in or sign-out (#3748). The fix (#3770) shipped in 20.1.1 and 21.0.0-rc.2, so both now import it from @angular/fire/auth, and the guide's note lists the releases that still need the workaround. The v21 upgrade guide covered only getImagenModel. firebase 12.18 removed every Imagen export, and the migration warns about getImagenModel only in files that imported an old Vertex AI entry point. Fixes #3815 Fixes #3816
Fixes #3748
Restores
beforeAuthStateChanged: { blockUntilFirst: false }, which #3590 added and #3613 dropped without comment.Changes
@angular/fire/authwrapsbeforeAuthStateChangedwithblockUntilFirstset totrue, so registering the hook adds a pending task that clears only when the callback first runs. Firebase runs this callback only on a sign-in or sign-out, so for a visitor who does neither, the app never becomes stable.ApplicationRef.whenStable()never resolves.ng buildfails during route extraction, and a server that renders per request never responds.onMessagedoes.beforeAuthStateChangedshould not block". zone log verbosity #3613 removed it at the spot where it added log-level overrides, and none of the issues zone log verbosity #3613 fixed involve this function, so the removal looks accidental.docs/auth.mdand the sample keep importingbeforeAuthStateChangedfromfirebase/authuntil a release carries this fix.Verification
On an Angular 21.2 server-rendered app, comparing
21.0.0-rc.1with a build of this branch:ng buildon rc.1 fails after 34 seconds withRoutes extraction was aborted. TimeoutError. With this branch it succeeds.docs/auth.md, which registers the hook only in the browser: on rc.1 the app did not become stable within 10 seconds. With this branch it became stable after 25 milliseconds.npm run test:node: 331 specs, 0 failures.npm run test:chrome-headless: 107 passed, 48 skipped.