Skip to content

FR: initializeServerApp automatic initialization #8863

Open
@jhuleatt

Description

@jhuleatt

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();

Activity

added
newA new issue that hasn't be categoirzed as question, bug or feature request
on Mar 25, 2025
jhuleatt

jhuleatt commented on Mar 25, 2025

@jhuleatt
ContributorAuthor

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

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

const serverApp = initializeServerApp(initializeApp());
added and removed
newA new issue that hasn't be categoirzed as question, bug or feature request
on Mar 25, 2025
self-assigned this
on Mar 25, 2025
linked a pull request that will close this issue on May 1, 2025
lucasoares

lucasoares commented on May 5, 2025

@lucasoares

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?

justinmpier

justinmpier commented on May 30, 2025

@justinmpier

@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.

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

Metadata

Metadata

Assignees

Type

No type

Projects

No projects

Milestone

No milestone

Relationships

None yet

    Development

    Participants

    @justinmpier@jhuleatt@DellaBitta@lucasoares@google-oss-bot

    Issue actions

      FR: initializeServerApp automatic initialization · Issue #8863 · firebase/firebase-js-sdk