Skip to content

feat(app): add initializeBrowserOrServerApp for browser & server apps (21.1.x) - #3848

Open
armando-navarro wants to merge 2 commits into
angular:21.1.xfrom
armando-navarro:browser-or-server-app-21
Open

armando-navarro wants to merge 2 commits into
angular:21.1.xfrom
armando-navarro:browser-or-server-app-21

Conversation

@armando-navarro

Copy link
Copy Markdown
Collaborator

Refs #3843
Refs #3826

Cherry-picks of #3827 (c593ecd on main) and #3844 (74abd5a on main) onto 21.1.x, so both ship in 21.1.0. #3827 comes first because #3844's spec files build on it. Both apply with no conflicts in that order.

On this branch: build and lint clean, test:node 420 specs with 0 failures on Node 20 and Node 22, and the Chrome headless suite green.

…#3827)

ɵzoneWrap holds a pending task from the moment a wrapped call gets a
callback until that callback first runs. For onLog, onTokenChanged,
the Database child listeners (onChildAdded on an empty node, the other
three until a later change), off, enableLogging, and the rxfire
streams stateChanges and auditTrail, nothing guarantees that first
run, so ApplicationRef.isStable can stay false for good and an SSR
build's route extraction times out, as angular#3748 reported for
beforeAuthStateChanged. They keep logLevel WARN, so only the pending
task changes.

isSupported in remote-config is the twelfth: angular#3613 put its
blockUntilFirst: false entry in the rxfire block, which exports no
isSupported, so it never applied, and angular#3759 removed the dead entry.

Server renders no longer wait for onChildAdded's first batch (onValue,
object and list still wait), and off(ref, type, cb) still detaches
nothing, because the wrapper replaces the callback it is given.

fromRef takes the event to listen for, and one blockUntilFirst value
cannot fit both uses: value always fires on attach, while a child event
may never fire. A hand-written fromRef in overrides.ts wraps rxfire's
fromRef both ways and picks by event, so
fromRef(ref, ListenEvent.value) holds a server render like object(ref)
and child events do not.

Fixes angular#3826

(cherry picked from commit c593ecd)
…angular#3844)

* feat(app): add initializeBrowserOrServerApp for browser & server apps

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

* fix(app): keep the default release working when an ngOnDestroy throws

The object handed to the SDK as releaseOnDeref was kept alive by a
DestroyRef.onDestroy closure. R3Injector.destroy runs every service's
ngOnDestroy before it empties those closures, so a throw there left the
object reachable from the injector, and any listener that kept the
injector alive kept the server app alive with it. The object is now a
providedIn: 'root' service, which the finally of destroy drops whatever
threw before it. The timed mode still releases from DestroyRef.onDestroy
and a throw before it still skips that release, as the docs say.

New specs on the release path: the default release observed through
forced collections, a shared app with a positive releaseAfterRender
released once per render, a null JSON payload, the App Check half of
the token comparison, and a throwing ngOnDestroy next to a retained
injector reference. The test:node scripts pass --expose-gc for the
forced collections.

The resolve hook picks the exports entry the way Node does, the first
key in the map's order that is an active condition or default.

Refs angular#3844

(cherry picked from commit 74abd5a)
@armando-navarro armando-navarro added bump: minor Size of the change: a new capability with no breaking change comp: app-check App Check (src/app-check). comp: auth Authentication (src/auth). comp: core FirebaseApp DI core (src/app). comp: database Realtime Database (src/database). comp: remote-config Remote Config (src/remote-config). comp: ssr Server-side rendering, hydration, @angular/ssr interop. comp: zones Change detection / zone.js / zoneless. type: feature New capability or enhancement. labels Nov 18, 2026
@armando-navarro armando-navarro added this to the 21.1.0 milestone Nov 18, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

bump: minor Size of the change: a new capability with no breaking change comp: app-check App Check (src/app-check). comp: auth Authentication (src/auth). comp: core FirebaseApp DI core (src/app). comp: database Realtime Database (src/database). comp: remote-config Remote Config (src/remote-config). comp: ssr Server-side rendering, hydration, @angular/ssr interop. comp: zones Change detection / zone.js / zoneless. type: feature New capability or enhancement.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant