firebase-js-sdk icon indicating copy to clipboard operation
firebase-js-sdk copied to clipboard

FR: initializeServerApp automatic initialization

Open jhuleatt opened this issue 8 months ago • 3 comments

Operating System

n/a

Environment (if applicable)

Node.js

Firebase SDK Version

n/a

Firebase SDK Product(s)

app (https://firebase.google.com/docs/reference/js/app.firebaseserverapp)

Project Tooling

Server-rendered web app

Detailed Problem Description

Now that initializeApp supports no-argument initialization (release note, implemented in #8483), it would be great if initializeServerApp did the same. This would allow SSR web apps to use no-args init both on the server and the client.

Steps and code to reproduce issue

const serverApp = initializeServerApp();

jhuleatt avatar Mar 25 '25 14:03 jhuleatt

A workaround is to pass an auto-initialized FirebaseApp instance to initializeServerApp:

import { initializeApp, initializeServerApp } from 'firebase/app'

const serverApp = initializeServerApp(initializeApp());

jhuleatt avatar Mar 25 '25 14:03 jhuleatt

A workaround is to pass an auto-initialized FirebaseApp instance to initializeServerApp:

import { initializeApp, initializeServerApp } from 'firebase/app'

const serverApp = initializeServerApp(initializeApp());

I'm trying your workaround and I'm getting a stack overflow error:

 ⨯ RangeError: Maximum call stack size exceeded
    at String.replace (<anonymous>) {
  digest: '2947813221'
}

I'm implementing the same cookie-based authentication strategy used in the friendlyeats-web Next.js sample. After a successful login, everything works fine, until I reload the page. On reload, the app crashes.

Previously, I was using initializeApp alone, and everything worked as expected... Any idea why?

lucasoares avatar May 05 '25 04:05 lucasoares

@lucasoares in nextjs you may want to send over only the necessary user info from the server to the client, vs the actual firebase user object.

justinmpier avatar May 30 '25 23:05 justinmpier

I'm having issues with this for final angular 20 deployment:

My firebaseserver app thinks it's in the browser

chakrachi avatar Jun 26 '25 06:06 chakrachi

Maximum call stack size exceeded same issue with me after reload app

ccctask avatar Jul 08 '25 08:07 ccctask