Repository navigation
feat(app): add initializeBrowserOrServerApp for browser & server apps - #3844
Open
armando-navarro wants to merge 2 commits into
Open
armando-navarro wants to merge 2 commits into
armando-navarro wants to merge 2 commits into
Conversation
One call inside provideFirebaseApp that returns the ordinary app in the browser and, on the server, a FirebaseServerApp for the visitor's ID token and App Check token, read from REQUEST_CONTEXT or passed in the settings. With neither token it returns the ordinary app. The server app is released when the render is garbage collected, as the releaseOnDeref setup in the guide does. releaseAfterRender opts into a release at render end or a fixed time after it. A token Firebase cannot parse now renders signed out with one warning instead of an HTTP 500. In dev mode a request with no request context is noted once. The App Check server warning now says which renders send no token. The Node specs can import the built library through a resolve hook. Fixes angular#3843
This was referenced Nov 10, 2026
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Fixes #3843
docs/auth.md,docs/app-check.mdanddocs/version-22-upgrade.mdchanges go on the rc.1 docs pull request, docs: document the 22.0.0-rc.1 changes #3835, which merges just before the tag.src/app/browser-or-server-app.jasmine.ts.src/app/app.spec.tsand two insrc/app-check/app-check.spec.ts.yarn install,yarn testrun successfully? yes, with npm:npm ci,npm run build,npm run lint,npm run test:nodeon Node 22, 24 and 26, andnpm run test:chrome-headless.Description
This adds
initializeBrowserOrServerAppto@angular/fire/app, one call insideprovideFirebaseAppthat returns the ordinary app in the browser and aFirebaseServerAppfor the visitor's tokens on the server. It replaces the callback the Authentication guide asks server-rendered apps to write. The reasoning is in the linked issue.Changes
src/app/browser-or-server-app.ts, exported from@angular/fire/app:initializeBrowserOrServerApp(options, settings?). On the server it readsauthIdTokenandappCheckTokenfromREQUEST_CONTEXT, or fromsettingswhen passed there, and builds a server app when either is present.releaseOnDerefworks, so a repeat request from the same visitor reuses it.settings.releaseAfterRenderopts into a release at render end (0) or that many milliseconds after it.FinalizationRegistrythe release is at render end.releaseOnDerefis typednever, and stripped at runtime, so one server app is never released twice.SyntaxErrororTypeError) returns the ordinary app after one fixed warning per process, then one line per hundred. EveryFirebaseErrorstill propagates.src/app-check/app-check.module.ts: the dev-mode server warning now says that server renders without a relayed App Check token send none, and points at the new function.src/app/app.ts: the comment's usage example no longer showsdeleteAppon the injected app.tools/angular-fire-resolve-hook.mjsandtools/jasmine-register-angular-fire.mjs, preloaded bytest:nodeandtest:node-esm: a resolve hook that maps@angular/fireimports to the built library, so Node specs can import it. No Node spec could before.Behavior to know
provideFirebaseAppand passinject(FirebaseApp)to every product provider, as the guide says.deleteAppon the injected app when using the function. It releases the server app itself.releaseAfterRender: 0every repeat request pays that cost again, which the docs state.releaseAfterRenderset, a service whosengOnDestroythrows stops Angular's teardown before the release runs, and that render's server app stays behind. The default release is not affected.Verified outside CI
On a fresh Angular 22 app wired by following the rewritten guide literally, against a real project:
releaseAfterRender: 0, after about a second with1000). Also underng serveand in an NgModule-bootstrapped app.app.config.client.tsandapp.config.server.tslayout renders signed out and signed in. The production browser bundle is the same size with and without the function.firebase/firestoreread still pending when the app is released at render end resolves normally, and a client abort mid-render lets the render finish and release its app.Tyler, the part I'd most like a second look at is the release in
buildServerApp: the default hands the SDK a holder object kept alive only by the render's injector, and the timed mode releases from the injector'sonDestroy.