Skip to content

(feat) initializeServerApp support for App Hosting auto init #9151

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 12 commits into from
Jul 12, 2025

Conversation

DellaBitta
Copy link
Contributor

Discussion

Implement Auto Init for initializeServerApp.

Auto init was previously implemented for initializeApp in #8483. This PR adds the same functionality to the initializeServerApp API surface.

Fixes #8863.

Testing

Local testing in Node and a Next.js app.

API Changes

Internal doc: Firebase API - JS SDK initializeServerApp auto init

@DellaBitta DellaBitta requested review from a team as code owners July 7, 2025 14:01
Copy link

changeset-bot bot commented Jul 7, 2025

🦋 Changeset detected

Latest commit: 8d93ef2

The changes in this PR will be included in the next version bump.

This PR includes changesets to release 3 packages
Name Type
@firebase/app Minor
firebase Minor
@firebase/app-compat Patch

Not sure what this means? Click here to learn what changesets are.

Click here if you're a maintainer who wants to add another changeset to this PR

@google-oss-bot
Copy link
Contributor

google-oss-bot commented Jul 7, 2025

Size Report 1

Affected Products

  • @firebase/app

    TypeBase (f11b552)Merge (bb0c09f)Diff
    browser19.5 kB20.0 kB+507 B (+2.6%)
    main20.4 kB20.9 kB+549 B (+2.7%)
    module19.5 kB20.0 kB+507 B (+2.6%)
    react-native20.4 kB20.9 kB+549 B (+2.7%)
  • @firebase/database-compat/standalone

    TypeBase (f11b552)Merge (bb0c09f)Diff
    main366 kB367 kB+549 B (+0.1%)
  • firebase

    TypeBase (f11b552)Merge (bb0c09f)Diff
    firebase-app-compat.js31.8 kB32.0 kB+232 B (+0.7%)
    firebase-app.js103 kB104 kB+928 B (+0.9%)
    firebase-compat.js806 kB807 kB+235 B (+0.0%)
    firebase-performance-standalone-compat.js105 kB106 kB+237 B (+0.2%)

Test Logs

  1. https://storage.googleapis.com/firebase-sdk-metric-reports/BqeCLNTixZ.html

@google-oss-bot
Copy link
Contributor

google-oss-bot commented Jul 7, 2025

Size Analysis Report 1

Affected Products

  • @firebase/app

    • _isFirebaseServerAppSettings

      Size

      TypeBase (f11b552)Merge (bb0c09f)Diff
      size?8.82 kB? (?)
      size-with-ext-deps?18.3 kB? (?)

      Dependency

      TypeBase (f11b552)Merge (bb0c09f)Diff
      functions?

      15 dependencies

      _addComponent
      _isFirebaseApp
      _isFirebaseServerAppSettings
      _registerComponent
      computeKey
      countBytes
      extractHeartbeatsForHeader
      getDbPromise
      getEarliestHeartbeatIdx
      getUTCDateString
      isVersionServiceProvider
      readHeartbeatsFromIndexedDB
      registerCoreComponents
      registerVersion
      writeHeartbeatsToIndexedDB

      ?
      classes?

      HeartbeatServiceImpl
      HeartbeatStorageImpl
      PlatformLoggerServiceImpl

      ?
      variables?

      41 dependencies

      DB_NAME
      DB_VERSION
      ERRORS
      ERROR_FACTORY
      MAX_HEADER_BYTES
      MAX_NUM_STORED_HEARTBEATS
      PLATFORM_LOG_STRING
      STORE_NAME
      _apps
      _components
      _serverApps
      dbPromise
      logger
      name
      name$1
      name$2
      name$3
      name$4
      name$5
      name$6
      name$7
      name$8
      name$9
      name$a
      name$b
      name$c
      name$d
      name$e
      name$f
      name$g
      name$h
      name$i
      name$j
      name$k
      name$l
      name$m
      name$n
      name$o
      name$p
      name$q
      version$1

      ?
      enums??

      External Dependency

      ModuleBase (f11b552)Merge (bb0c09f)Diff
      @firebase/component?

      Component

      ?
      @firebase/logger?

      Logger

      ?
      @firebase/util?

      ErrorFactory
      FirebaseError
      base64urlEncodeWithoutPadding
      isIndexedDBAvailable
      validateIndexedDBOpenable

      ?
      idb?

      openDB

      ?
    • initializeServerApp

      Size

      TypeBase (f11b552)Merge (bb0c09f)Diff
      size12.3 kB12.6 kB+258 B (+2.1%)
      size-with-ext-deps26.3 kB27.4 kB+1.04 kB (+4.0%)

      Dependency

      TypeBase (f11b552)Merge (bb0c09f)Diff
      functions

      17 dependencies

      _addComponent
      _isFirebaseApp
      _registerComponent
      computeKey
      countBytes
      deleteApp
      extractHeartbeatsForHeader
      getDbPromise
      getEarliestHeartbeatIdx
      getUTCDateString
      initializeServerApp
      isVersionServiceProvider
      readHeartbeatsFromIndexedDB
      registerCoreComponents
      registerVersion
      validateTokenTTL
      writeHeartbeatsToIndexedDB

      18 dependencies

      _addComponent
      _isFirebaseApp
      _isFirebaseServerAppSettings
      _registerComponent
      computeKey
      countBytes
      deleteApp
      extractHeartbeatsForHeader
      getDbPromise
      getEarliestHeartbeatIdx
      getUTCDateString
      initializeServerApp
      isVersionServiceProvider
      readHeartbeatsFromIndexedDB
      registerCoreComponents
      registerVersion
      validateTokenTTL
      writeHeartbeatsToIndexedDB

      + _isFirebaseServerAppSettings

      External Dependency

      ModuleBase (f11b552)Merge (bb0c09f)Diff
      @firebase/util

      ErrorFactory
      FirebaseError
      base64Decode
      base64urlEncodeWithoutPadding
      isBrowser
      isIndexedDBAvailable
      isWebWorker
      validateIndexedDBOpenable

      ErrorFactory
      FirebaseError
      base64Decode
      base64urlEncodeWithoutPadding
      getDefaultAppConfig
      isBrowser
      isIndexedDBAvailable
      isWebWorker
      validateIndexedDBOpenable

      + getDefaultAppConfig

Test Logs

  1. https://storage.googleapis.com/firebase-sdk-metric-reports/0K78QF6kMU.html

@DellaBitta DellaBitta requested review from a team as code owners July 7, 2025 15:02
@DellaBitta DellaBitta changed the title (feat) initializeServerApp support for App Hosting Auto Init (feat) initializeServerApp support for App Hosting auto init Jul 7, 2025
Comment on lines 235 to 243
/**
* Creates and initializes a {@link @firebase/app#FirebaseServerApp} instance.
*
* @param config - Optional `FirebaseServerApp` configuration.
*
* @returns The initialized `FirebaseServerApp`.
*
* @public
*/
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think it's useful to add @throws tag on functions that throw, but the other functions in app don't do this, so maybe it'd just make it inconsistent which may be worse- feel free to ignore.

@throws {AppError.INVALID_SERVER_APP_ENVIRONMENT} - ... 


if (_options) {
if (_isFirebaseApp(_options)) {
app = _options;
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It looks like this is the only place the app variable is used, probably don't need to initialize it with the let above in line 256.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Fixed.

): FirebaseServerApp {
if (isBrowser() && !isWebWorker()) {
// FirebaseServerApp isn't designed to be run in browsers.
throw ERROR_FACTORY.create(AppError.INVALID_SERVER_APP_ENVIRONMENT);
}

if (_serverAppConfig.automaticDataCollectionEnabled === undefined) {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Are we getting rid of this? Should this go in the second branch of the if/else? Maybe also the third?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yes, thank you, nice catch!

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Fixed.

@DellaBitta DellaBitta requested a review from hsubox76 July 8, 2025 14:31
Copy link
Contributor

@egilmorez egilmorez left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM!

Would this have any impact on https://firebase.devsite.corp.google.com/docs/app-hosting/firebase-sdks or other App Hosting pages? Or possibly https://firebase.google.com/docs/web/ssr-apps?

@DellaBitta
Copy link
Contributor Author

Would this have any impact on https://firebase.devsite.corp.google.com/docs/app-hosting/firebase-sdks or other App Hosting pages?

Yes, I think that page should be updated. Both the "Automatically initialize Firebase Admin SDK and web SDKs" and "Use FirebaseServerApp for SSR" sections. Hit up @jamesdaniels and me to get the ball rolling there.

Or possibly https://firebase.google.com/docs/web/ssr-apps?

I don't think this page needs any updates. It doesn't mention auto-initialization at all, and I don't think we want to push for its usage outside of App Hosting context.

@DellaBitta DellaBitta merged commit d91169f into main Jul 12, 2025
49 checks passed
@DellaBitta DellaBitta deleted the ddb-serverapp-autoinit branch July 12, 2025 00:50
@google-oss-bot google-oss-bot mentioned this pull request Jul 15, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

FR: initializeServerApp automatic initialization
5 participants