Skip to content

Firebase API called outside injection context #3605

Description

@EthanSK

Getting this console warning everywhere in my app thats using firebase, even within injection contexts

here are my deps

"@angular/animations": "~19.0.0",
    "@angular/cdk": "~19.0.2",
    "@angular/common": "~19.0.0",
    "@angular/compiler": "~19.0.0",
    "@angular/core": "~19.0.0",
    "@angular/fire": "19.0.0-rc.4",
    "@angular/forms": "~19.0.0",
    "@angular/material": "~19.0.2",
    "@angular/platform-browser": "~19.0.0",
    "@angular/platform-browser-dynamic": "~19.0.0",
    "@angular/platform-server": "~19.0.0",
    "@angular/router": "~19.0.0",
    "@angular/ssr": "~19.0.0",
    "@nestjs/axios": "^3.1.3",
    "@nestjs/common": "^10.0.2",
    "@nestjs/core": "^10.0.2",
    "@nestjs/platform-express": "^10.0.2",
    "@nestjs/swagger": "^8.1.0",
    "@ngrx/operators": "^19.0.0",
    "@ngrx/signals": "^19.0.0-rc.0",
    "app-root-path": "^3.1.0",
    "axios": "^1.7.9",
    "class-transformer": "^0.5.1",
    "class-validator": "^0.14.1",
    "copy-webpack-plugin": "^12.0.2",
    "depcheck": "^1.4.7",
    "express": "~4.18.2",
    "firebase": "^11.0.2",
    "firebase-admin": "^13.0.1",
    "firebase-functions": "^6.2.0",
    "firebaseui": "^6.1.0",
    "firebaseui-angular": "^6.3.0",
    "fs-extra": "^11.2.0",
    "nanoid": "^3.3.4",
    "ngx-device-detector": "^9.0.0",
    "reflect-metadata": "^0.1.13",
    "rxjs": "^7.8.0",
    "source-map-support": "^0.5.21",
    "spotify-uri": "^4.1.0",
    "stripe": "^17.4.0",
    "zone.js": "~0.15.0"

Activity

  1. google-oss-bot commented on Jan 2, 2025

    @google-oss-bot

    This issue does not seem to follow the issue template. Make sure you provide all the required information.

  2. pwejar commented on Jan 4, 2025

    @pwejar

    here is example of code that cause this issue. ssr standalone angular 19.`import {
    Component,
    effect,
    inject,
    Input,
    OnInit,
    signal,
    } from '@angular/core';
    import { CommonModule } from '@angular/common';
    import { FormsModule } from '@angular/forms';
    import {
    IonContent,
    IonHeader,
    IonTitle,
    IonToolbar,
    IonInfiniteScroll,
    InfiniteScrollCustomEvent,
    IonInfiniteScrollContent,
    } from '@ionic/angular/standalone';
    import { FirebaseService } from 'src/app/services/firebase.service';
    import { Folder, Item } from 'src/app/app.interface';
    import { ItemThumbnailComponent } from 'src/app/components/item-thumbnail/item-thumbnail.component';
    import { FolderComponent } from 'src/app/components/folder/folder.component';
    import {
    collection,
    getDocs,
    limit,
    query,
    where,
    } from '@angular/fire/firestore';

    @component({
    selector: 'app-items',
    templateUrl: './items.page.html',
    styleUrls: ['./items.page.scss'],
    standalone: true,
    imports: [
    IonContent,
    IonHeader,
    IonTitle,
    IonToolbar,
    CommonModule,
    FormsModule,
    ItemThumbnailComponent,
    FolderComponent,
    IonInfiniteScroll,
    IonInfiniteScrollContent,
    ],
    })
    export class ItemsPage implements OnInit {
    firebase: FirebaseService = inject(FirebaseService);
    count = signal(34);
    searchTerm!: string;
    searchedResults!: Item[];
    displayFolders!: Folder[];
    displayItems!: Item[];
    itemsLoading!: boolean;
    constructor() {
    effect(() => {
    if (this.firebase.store()) {
    this.displayFolders = this.firebase.store()!.folders;
    this.getItems();
    }
    });
    }

    ngOnInit() {}
    openFolder(folder: Folder, index: number) {
    console.log(folder);
    }
    async getItems() {
    this.itemsLoading = true;
    const collectionRef = collection(this.firebase.firestore, 'items');
    const collectionQuery = query(
    collectionRef,
    where('public', '==', true),
    where('storeID', '==', this.firebase.store()!.id),
    limit(this.count())
    );
    const collectionSnapShot = await getDocs(collectionQuery);
    const itemsHolder = collectionSnapShot.docs.map((doc) => ({
    id: doc.id,
    ...(doc.data() as Item),
    }));
    // console.log(itemsHolder)
    this.firebase.displayItems.update((oldItems: Item[]) => {
    const newItems = itemsHolder.filter(
    (newItem) => !oldItems.some((oldItem) => oldItem.id === newItem.id)
    );
    return [...oldItems, ...newItems];
    });
    this.itemsLoading = false;
    }
    onIonInfinite(event: InfiniteScrollCustomEvent) {
    this.count.update((oldCount) => oldCount + 30);
    setTimeout(() => {
    event.target.complete();
    }, 500);
    }
    }
    `

  3. galih9 commented on Mar 7, 2025

    @galih9

    its happening, its not blocker issue but still hapening in latest angular

  4. rgant commented on Mar 7, 2025

    @rgant

    @galih9 those messages are an intentional choice made by AngularFire. Angular version has nothing to do with it. They will keep happening until you wrap every AngularFire method in an injection context. (Which isn't trivial in all cases) Or you disable the logging

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

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