Skip to content

experimentalAutoDetectLongPolling not picked up via getFirestore when provided as configuration to initializeApp #3285

@AdditionAddict

Description

@AdditionAddict

Version info

Angular: 14

Firebase: 9

AngularFire: 7

Other (e.g. Ionic/Cordova, Node, browser, operating system): Firefox, Windows

How to reproduce these conditions

If I use the documented way of providing firestore and add experimentalForceLongPolling: true to my configuration provided to initializeApp this is ignored by getFirestore.

import { NgModule } from '@angular/core';

import { initializeApp, provideFirebaseApp } from '@angular/fire/app';
import { provideAuth, getAuth, connectAuthEmulator } from '@angular/fire/auth';
import { provideFirestore, getFirestore, connectFirestoreEmulator, initializeFirestore } from '@angular/fire/firestore';
import { environment } from '../environments/environment';

@NgModule({
  declarations: [],
  imports: [
    provideFirebaseApp(() => initializeApp(environment.firebase), // <------environment.firebase has experimentalForceLongPolling: true
    provideAuth(() =>  getAuth()),
    provideFirestore(() => getFirestore()) // getFirestore ignores provided environment.firebase
  ]
})
export class FirebaseV7Module { }
export const environment = {
  firebase: {
    apiKey: "...",
    authDomain: "...",
    projectId: "...",
    storageBucket: "...",
    messagingSenderId: "...",
    appId: "...",
    measurementId: "...",

    experimentalForceLongPolling: true // <--------
  }
};

I'm using the folling workaround:

import { NgModule } from '@angular/core';

import { initializeApp, provideFirebaseApp } from '@angular/fire/app';
import { provideAuth, getAuth, connectAuthEmulator } from '@angular/fire/auth';
import { provideFirestore, getFirestore, connectFirestoreEmulator, initializeFirestore } from '@angular/fire/firestore';
import { environment } from '../environments/environment';

@NgModule({
  declarations: [],
  imports: [
    ...
    provideFirestore(() => {
      let firestore;
      if (environment.useEmulators) {
        console.log("🔔 using firestore emulator...")
        // bug: experimentalAutoDetectLongPolling not picked up via `getFirestore`
        const app = initializeApp(environment.firebaseConfig)
        firestore = initializeFirestore(app, {
          experimentalAutoDetectLongPolling: true
        })
        connectFirestoreEmulator(firestore, 'localhost', 8080)
      } else {
        firestore = getFirestore();
      }
      return firestore;
    }),
  ]
})
export class FirebaseV7Module { }

Failing test unit, Stackblitz demonstrating the problem

Steps to set up and reproduce

Sample data and security rules

Debug output

** Errors in the JavaScript console **

** Output from firebase.database().enableLogging(true); **

** Screenshots **

Expected behavior

providing experimentalForceLongPolling: true to my configuration provided to initializeApp should (imo) be picked up by getFirestore

Actual behavior

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