Skip to content

Angular 11 Firebase Server-side rendering infinite loading / pending #2725

@Judp0m

Description

@Judp0m

Angular: 11

Firebase: 8.2.1

AngularFire: 6.1.4

How to reproduce these conditions

This works as expected in NON-SSR mode, to query once a given collection:

this.firestore.collection<T>('collection', ref => ref.limit(5))
    .get()
    .pipe(
      map((qs: firebase.firestore.QuerySnapshot) => qs.empty ? [] : qs.docs.map(d => d.data() as T)),
    );

When switching to SSR, the above code leads to the express server hanging, and the client see a 'pending' query that never completes, or hits a timeout and leaves the page partially rendered (i.e. without the results of that query).

This is the best workaround I found:

this.firestore.collection<T>('collection', ref => ref.limit(5))
    .valueChanges()   <<<<
    .pipe(
      take(2),        <<<<
    );

Though this more sane workaround also fails:

this.firestore.collection<T>('collection', ref => ref.limit(5))
    .valueChanges()
    .pipe(
      take(1),      <<<<
    );

More details about exact version used here:
https://stackoverflow.com/questions/65388261/angular-11-firebase-server-side-rendering-infinite-loading-pending/65388376#65388376

Expected behavior

The first version should work without the workaround, without and with SSR.

Actual behavior

Without the workaround, the express server hangs indefinitely.

Related issues:
firebase/firebase-js-sdk#3541
firebase/firebase-js-sdk#3542
angular/universal#1711

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions