Skip to content

Migrates Listeners Registration from getMessaging to Messaging's Factory Methods 🏭 #4918

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 8 commits into from
May 21, 2021

Conversation

zwu52
Copy link
Member

@zwu52 zwu52 commented May 17, 2021

messaging-compat is a compatibility layer that bridges the v8 and v9(modular) JS API. It's created through wrapping the v9 SDK to recreate the v8 API surface. The objective is to allow developer to gradually migrate to v9 without having to migrate the entire codebase.

Now the v9 SDK registers its listeners (onPush, onSubChange, onMessage) in getMessagingInWindow and getMessagaingInSw which is not called in the messaging-compat. Without these listeners, the compat SDK can only getToken and not get callbacks in onMessage and onBackgroundMessage

  • PR moves the listeners registration to factory methods.
  • PR also removes unused variables in messaging-compat.
  • PR registers 2 components since they will both be called in messaging-compat as messaging-exp and messaging-sw-exp

b/188418727 for tracking

@changeset-bot
Copy link

changeset-bot bot commented May 17, 2021

⚠️ No Changeset found

Latest commit: 1a47364

Merging this PR will not cause a version bump for any packages. If these changes should not result in a new version, you're good to go. If these changes should result in a version bump, you need to add a changeset.

This PR includes no changesets

When changesets are added to this PR, you'll see the packages that this PR includes changesets for and the associated semver types

Click here to learn what changesets are, and how to add one.

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

@google-oss-bot
Copy link
Contributor

google-oss-bot commented May 17, 2021

Binary Size Report

Affected SDKs

  • @firebase/analytics

    Type Base (50860d7) Head (0c72756) Diff
    esm2017 ? 18.7 kB ? (?)
    main ? 24.2 kB ? (?)
    module ? 23.4 kB ? (?)
  • @firebase/api-documenter

    Type Base (50860d7) Head (0c72756) Diff
    main ? 3.72 kB ? (?)
  • @firebase/app

    Type Base (50860d7) Head (0c72756) Diff
    browser ? 11.0 kB ? (?)
    esm2017 ? 9.81 kB ? (?)
    lite ? 8.95 kB ? (?)
    lite-esm2017 ? 7.93 kB ? (?)
    main ? 10.2 kB ? (?)
    module ? 11.0 kB ? (?)
    react-native ? 9.87 kB ? (?)
  • @firebase/app-check

    Type Base (50860d7) Head (0c72756) Diff
    browser ? 20.9 kB ? (?)
    esm2017 ? 17.3 kB ? (?)
    main ? 20.9 kB ? (?)
    module ? 20.5 kB ? (?)
  • @firebase/auth

    Type Base (50860d7) Head (0c72756) Diff
    browser ? 181 kB ? (?)
    main ? 181 kB ? (?)
    module ? 181 kB ? (?)
  • @firebase/component

    Type Base (50860d7) Head (0c72756) Diff
    browser ? 7.84 kB ? (?)
    esm2017 ? 5.88 kB ? (?)
    main ? 8.18 kB ? (?)
    module ? 7.84 kB ? (?)
  • @firebase/database

    Type Base (50860d7) Head (0c72756) Diff
    browser ? 296 kB ? (?)
    esm2017 ? 265 kB ? (?)
    main ? 299 kB ? (?)
    module ? 296 kB ? (?)
  • @firebase/database-compat

    Type Base (50860d7) Head (0c72756) Diff
    browser ? 86.5 kB ? (?)
    main ? 103 kB ? (?)
    module ? 86.5 kB ? (?)
  • @firebase/database-exp

    Type Base (50860d7) Head (0c72756) Diff
    browser ? 246 kB ? (?)
    main ? 278 kB ? (?)
    module ? 246 kB ? (?)
  • @firebase/firestore

    Type Base (50860d7) Head (0c72756) Diff
    browser ? 284 kB ? (?)
    esm2017 ? 226 kB ? (?)
    main ? 531 kB ? (?)
    module ? 284 kB ? (?)
    react-native ? 226 kB ? (?)
  • @firebase/firestore-compat

    Type Base (50860d7) Head (0c72756) Diff
    browser ? 28.9 kB ? (?)
    main ? 38.1 kB ? (?)
    module ? 28.9 kB ? (?)
    react-native ? 28.7 kB ? (?)
  • @firebase/firestore-exp

    Type Base (50860d7) Head (0c72756) Diff
    browser ? 224 kB ? (?)
    main ? 510 kB ? (?)
    module ? 224 kB ? (?)
    react-native ? 224 kB ? (?)
  • @firebase/firestore-lite

    Type Base (50860d7) Head (0c72756) Diff
    browser ? 72.4 kB ? (?)
    main ? 149 kB ? (?)
    module ? 72.4 kB ? (?)
    react-native ? 72.6 kB ? (?)
  • @firebase/firestore/bundle

    Type Base (50860d7) Head (0c72756) Diff
    browser ? 290 kB ? (?)
    esm2017 ? 176 kB ? (?)
    main ? 527 kB ? (?)
    module ? 290 kB ? (?)
    react-native ? 176 kB ? (?)
  • @firebase/firestore/memory

    Type Base (50860d7) Head (0c72756) Diff
    browser ? 216 kB ? (?)
    esm2017 ? 172 kB ? (?)
    main ? 325 kB ? (?)
    module ? 216 kB ? (?)
    react-native ? 172 kB ? (?)
  • @firebase/firestore/memory-bundle

    Type Base (50860d7) Head (0c72756) Diff
    browser ? 224 kB ? (?)
    esm2017 ? 176 kB ? (?)
    main ? 322 kB ? (?)
    module ? 224 kB ? (?)
    react-native ? 176 kB ? (?)
  • @firebase/functions

    Type Base (50860d7) Head (0c72756) Diff
    browser ? 10.7 kB ? (?)
    esm2017 ? 8.15 kB ? (?)
    main ? 11.1 kB ? (?)
    module ? 10.7 kB ? (?)
  • @firebase/installations

    Type Base (50860d7) Head (0c72756) Diff
    esm2017 ? 16.6 kB ? (?)
    main ? 22.2 kB ? (?)
    module ? 21.6 kB ? (?)
  • @firebase/logger

    Type Base (50860d7) Head (0c72756) Diff
    esm2017 ? 3.25 kB ? (?)
    main ? 5.38 kB ? (?)
    module ? 4.65 kB ? (?)
  • @firebase/messaging

    Type Base (50860d7) Head (0c72756) Diff
    esm2017 ? 26.2 kB ? (?)
    main ? 34.9 kB ? (?)
    module ? 34.4 kB ? (?)
  • @firebase/performance

    Type Base (50860d7) Head (0c72756) Diff
    browser ? 27.7 kB ? (?)
    esm2017 ? 25.9 kB ? (?)
    main ? 28.0 kB ? (?)
    module ? 27.7 kB ? (?)
  • @firebase/polyfill

    Type Base (50860d7) Head (0c72756) Diff
    main ? 747 B ? (?)
    module ? 705 B ? (?)
  • @firebase/remote-config

    Type Base (50860d7) Head (0c72756) Diff
    browser ? 22.4 kB ? (?)
    esm2017 ? 17.4 kB ? (?)
    main ? 23.0 kB ? (?)
    module ? 22.4 kB ? (?)
  • @firebase/rules-unit-testing

    Type Base (50860d7) Head (0c72756) Diff
    main ? 14.8 kB ? (?)
  • @firebase/storage

    Type Base (50860d7) Head (0c72756) Diff
    browser ? 63.4 kB ? (?)
    esm2017 ? 54.6 kB ? (?)
    main ? 63.8 kB ? (?)
    module ? 63.4 kB ? (?)
  • @firebase/storage-compat

    Type Base (50860d7) Head (0c72756) Diff
    browser ? 10.2 kB ? (?)
    main ? 29.1 kB ? (?)
    module ? 10.2 kB ? (?)
  • @firebase/storage-exp

    Type Base (50860d7) Head (0c72756) Diff
    browser ? 51.5 kB ? (?)
    main ? 52.6 kB ? (?)
    module ? 51.5 kB ? (?)
  • @firebase/util

    Type Base (50860d7) Head (0c72756) Diff
    browser ? 21.2 kB ? (?)
    esm2017 ? 20.0 kB ? (?)
    main ? 25.8 kB ? (?)
    module ? 21.2 kB ? (?)
  • @firebase/webchannel-wrapper

    Type Base (50860d7) Head (0c72756) Diff
    esm2017 ? 39.5 kB ? (?)
    main ? 46.9 kB ? (?)
    module ? 40.8 kB ? (?)
  • firebase

    Click to show 16 binary size changes.
    Type Base (50860d7) Head (0c72756) Diff
    firebase-analytics.js ? 35.8 kB ? (?)
    firebase-app-check.js ? 22.2 kB ? (?)
    firebase-app.js ? 21.8 kB ? (?)
    firebase-auth.js ? 177 kB ? (?)
    firebase-database.js ? 187 kB ? (?)
    firebase-firestore.js ? 332 kB ? (?)
    firebase-firestore.memory.js ? 267 kB ? (?)
    firebase-functions.js ? 10.8 kB ? (?)
    firebase-installations.js ? 19.3 kB ? (?)
    firebase-messaging.js ? 41.0 kB ? (?)
    firebase-performance-standalone.es2017.js ? 73.1 kB ? (?)
    firebase-performance-standalone.js ? 49.7 kB ? (?)
    firebase-performance.js ? 38.3 kB ? (?)
    firebase-remote-config.js ? 36.9 kB ? (?)
    firebase-storage.js ? 41.6 kB ? (?)
    firebase.js ? 889 kB ? (?)

Test Logs

@google-oss-bot
Copy link
Contributor

google-oss-bot commented May 17, 2021

Size Analysis Report

Affected Products

  • @firebase/functions-exp

    • getFunctions

      Size Table

      TypeBase (50860d7)Head (0c72756)Diff
      size
      2.07 kB
      2.08 kB
      +6 B (+0.3%)
      size-with-ext-deps
      7.95 kB
      7.95 kB
      +6 B (+0.1%)
    • httpsCallable

      Size Table

      TypeBase (50860d7)Head (0c72756)Diff
      size
      5.41 kB
      5.42 kB
      +6 B (+0.1%)
      size-with-ext-deps
      10.7 kB
      10.7 kB
      +6 B (+0.1%)
    • useFunctionsEmulator

      Size Table

      TypeBase (50860d7)Head (0c72756)Diff
      size
      2.04 kB
      2.05 kB
      +6 B (+0.3%)
      size-with-ext-deps
      6.66 kB
      6.66 kB
      +6 B (+0.1%)
  • @firebase/messaging-exp

    • deleteToken

      Size Table

      TypeBase (50860d7)Head (0c72756)Diff
      size
      7.47 kB
      8.93 kB
      +1.46 kB (+19.5%)
      size-with-ext-deps
      25.2 kB
      26.7 kB
      +1.49 kB (+5.9%)

      Dependency Table

      TypeBase (50860d7)Head (0c72756)Diff
      functions

      18 dependencies

      arrayToBase64
      checkTokenDetails
      dbGet
      dbRemove
      dbSet
      deleteToken
      deleteTokenInternal
      extractAppConfig
      getDbPromise
      getEndpoint
      getHeaders
      getKey
      getMissingValueError
      isWindowSupported
      migrateOldDatabase
      registerDefaultSw
      registerMessagingInWindow
      requestDeleteToken
      

      26 dependencies

      arrayToBase64
      checkTokenDetails
      dbGet
      dbRemove
      dbSet
      deleteToken
      deleteTokenInternal
      externalizePayload
      extractAppConfig
      getDbPromise
      getEndpoint
      getEventType
      getHeaders
      getKey
      getMissingValueError
      isConsoleMessage
      isWindowSupported
      logToScion
      messageEventListener
      migrateOldDatabase
      propagateDataPayload
      propagateFcmOptions
      propagateNotificationPayload
      registerDefaultSw
      registerMessagingInWindow
      requestDeleteToken
      

      + externalizePayload
      + getEventType
      + isConsoleMessage
      + logToScion
      + messageEventListener
      + propagateDataPayload
      + propagateFcmOptions
      + propagateNotificationPayload

      variables

      14 dependencies

      DATABASE_NAME
      DATABASE_VERSION
      DEFAULT_SW_PATH
      DEFAULT_SW_SCOPE
      ENDPOINT
      ERROR_FACTORY
      ERROR_MAP
      MessageType
      OBJECT_STORE_NAME
      OLD_DB_NAME
      OLD_DB_VERSION
      OLD_OBJECT_STORE_NAME
      WindowMessagingFactory
      dbPromise
      

      18 dependencies

      CONSOLE_CAMPAIGN_ANALYTICS_ENABLED
      CONSOLE_CAMPAIGN_ID
      CONSOLE_CAMPAIGN_NAME
      CONSOLE_CAMPAIGN_TIME
      DATABASE_NAME
      DATABASE_VERSION
      DEFAULT_SW_PATH
      DEFAULT_SW_SCOPE
      ENDPOINT
      ERROR_FACTORY
      ERROR_MAP
      MessageType
      OBJECT_STORE_NAME
      OLD_DB_NAME
      OLD_DB_VERSION
      OLD_OBJECT_STORE_NAME
      WindowMessagingFactory
      dbPromise
      

      + CONSOLE_CAMPAIGN_ANALYTICS_ENABLED
      + CONSOLE_CAMPAIGN_ID
      + CONSOLE_CAMPAIGN_NAME
      + CONSOLE_CAMPAIGN_TIME

    • getMessaging

      Size Table

      TypeBase (50860d7)Head (0c72756)Diff
      size
      5.11 kB
      5.09 kB
      -14 B (-0.3%)
      size-with-ext-deps
      23.4 kB
      23.4 kB
      -14 B (-0.1%)
    • getToken

      Size Table

      TypeBase (50860d7)Head (0c72756)Diff
      size
      10.5 kB
      12.0 kB
      +1.49 kB (+14.1%)
      size-with-ext-deps
      28.3 kB
      29.8 kB
      +1.49 kB (+5.3%)

      Dependency Table

      TypeBase (50860d7)Head (0c72756)Diff
      functions

      29 dependencies

      arrayToBase64
      base64ToArray
      checkTokenDetails
      dbGet
      dbRemove
      dbSet
      deleteTokenInternal
      extractAppConfig
      getBody
      getDbPromise
      getEndpoint
      getHeaders
      getKey
      getMissingValueError
      getNewToken
      getPushSubscription
      getToken
      getTokenInternal
      isTokenValid
      isWindowSupported
      migrateOldDatabase
      registerDefaultSw
      registerMessagingInWindow
      requestDeleteToken
      requestGetToken
      requestUpdateToken
      updateSwReg
      updateToken
      updateVapidKey
      

      37 dependencies

      arrayToBase64
      base64ToArray
      checkTokenDetails
      dbGet
      dbRemove
      dbSet
      deleteTokenInternal
      externalizePayload
      extractAppConfig
      getBody
      getDbPromise
      getEndpoint
      getEventType
      getHeaders
      getKey
      getMissingValueError
      getNewToken
      getPushSubscription
      getToken
      getTokenInternal
      isConsoleMessage
      isTokenValid
      isWindowSupported
      logToScion
      messageEventListener
      migrateOldDatabase
      propagateDataPayload
      propagateFcmOptions
      propagateNotificationPayload
      registerDefaultSw
      registerMessagingInWindow
      requestDeleteToken
      requestGetToken
      requestUpdateToken
      updateSwReg
      updateToken
      updateVapidKey
      

      + externalizePayload
      + getEventType
      + isConsoleMessage
      + logToScion
      + messageEventListener
      + propagateDataPayload
      + propagateFcmOptions
      + propagateNotificationPayload

      variables

      16 dependencies

      DATABASE_NAME
      DATABASE_VERSION
      DEFAULT_SW_PATH
      DEFAULT_SW_SCOPE
      DEFAULT_VAPID_KEY
      ENDPOINT
      ERROR_FACTORY
      ERROR_MAP
      MessageType
      OBJECT_STORE_NAME
      OLD_DB_NAME
      OLD_DB_VERSION
      OLD_OBJECT_STORE_NAME
      TOKEN_EXPIRATION_MS
      WindowMessagingFactory
      dbPromise
      

      20 dependencies

      CONSOLE_CAMPAIGN_ANALYTICS_ENABLED
      CONSOLE_CAMPAIGN_ID
      CONSOLE_CAMPAIGN_NAME
      CONSOLE_CAMPAIGN_TIME
      DATABASE_NAME
      DATABASE_VERSION
      DEFAULT_SW_PATH
      DEFAULT_SW_SCOPE
      DEFAULT_VAPID_KEY
      ENDPOINT
      ERROR_FACTORY
      ERROR_MAP
      MessageType
      OBJECT_STORE_NAME
      OLD_DB_NAME
      OLD_DB_VERSION
      OLD_OBJECT_STORE_NAME
      TOKEN_EXPIRATION_MS
      WindowMessagingFactory
      dbPromise
      

      + CONSOLE_CAMPAIGN_ANALYTICS_ENABLED
      + CONSOLE_CAMPAIGN_ID
      + CONSOLE_CAMPAIGN_NAME
      + CONSOLE_CAMPAIGN_TIME

    • isSupported

      Size Table

      TypeBase (50860d7)Head (0c72756)Diff
      size
      3.52 kB
      4.98 kB
      +1.46 kB (+41.5%)
      size-with-ext-deps
      21.1 kB
      22.6 kB
      +1.49 kB (+7.0%)

      Dependency Table

      TypeBase (50860d7)Head (0c72756)Diff
      functions

      extractAppConfig
      getMissingValueError
      isSupported
      registerMessagingInWindow
      

      12 dependencies

      externalizePayload
      extractAppConfig
      getEventType
      getMissingValueError
      isConsoleMessage
      isSupported
      logToScion
      messageEventListener
      propagateDataPayload
      propagateFcmOptions
      propagateNotificationPayload
      registerMessagingInWindow
      

      + externalizePayload
      + getEventType
      + isConsoleMessage
      + logToScion
      + messageEventListener
      + propagateDataPayload
      + propagateFcmOptions
      + propagateNotificationPayload

      variables

      ERROR_FACTORY
      ERROR_MAP
      MessageType
      WindowMessagingFactory
      

      CONSOLE_CAMPAIGN_ANALYTICS_ENABLED
      CONSOLE_CAMPAIGN_ID
      CONSOLE_CAMPAIGN_NAME
      CONSOLE_CAMPAIGN_TIME
      ERROR_FACTORY
      ERROR_MAP
      MessageType
      WindowMessagingFactory
      

      + CONSOLE_CAMPAIGN_ANALYTICS_ENABLED
      + CONSOLE_CAMPAIGN_ID
      + CONSOLE_CAMPAIGN_NAME
      + CONSOLE_CAMPAIGN_TIME

    • onMessage

      Size Table

      TypeBase (50860d7)Head (0c72756)Diff
      size
      3.71 kB
      5.17 kB
      +1.46 kB (+39.4%)
      size-with-ext-deps
      21.4 kB
      22.8 kB
      +1.49 kB (+7.0%)

      Dependency Table

      TypeBase (50860d7)Head (0c72756)Diff
      functions

      extractAppConfig
      getMissingValueError
      isWindowSupported
      onMessage
      registerMessagingInWindow
      

      13 dependencies

      externalizePayload
      extractAppConfig
      getEventType
      getMissingValueError
      isConsoleMessage
      isWindowSupported
      logToScion
      messageEventListener
      onMessage
      propagateDataPayload
      propagateFcmOptions
      propagateNotificationPayload
      registerMessagingInWindow
      

      + externalizePayload
      + getEventType
      + isConsoleMessage
      + logToScion
      + messageEventListener
      + propagateDataPayload
      + propagateFcmOptions
      + propagateNotificationPayload

      variables

      ERROR_FACTORY
      ERROR_MAP
      MessageType
      WindowMessagingFactory
      

      CONSOLE_CAMPAIGN_ANALYTICS_ENABLED
      CONSOLE_CAMPAIGN_ID
      CONSOLE_CAMPAIGN_NAME
      CONSOLE_CAMPAIGN_TIME
      ERROR_FACTORY
      ERROR_MAP
      MessageType
      WindowMessagingFactory
      

      + CONSOLE_CAMPAIGN_ANALYTICS_ENABLED
      + CONSOLE_CAMPAIGN_ID
      + CONSOLE_CAMPAIGN_NAME
      + CONSOLE_CAMPAIGN_TIME

@zwu52 zwu52 changed the title Add listeners registration to messaging-compat Migrates Listeners Registration from getMessaging to Messaging's Factory Methods 🏭 May 17, 2021
@zwu52 zwu52 requested a review from Feiyang1 May 17, 2021 23:40
Copy link
Member

@Feiyang1 Feiyang1 left a comment

Choose a reason for hiding this comment

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

In @firebase/messaging-compat, we need to check the environment, and get the correct provider (messaging-exp or messaging-sw-exp) depending on the environment.

https://github.com/firebase/firebase-js-sdk/blob/master/packages-exp/messaging-compat/src/registerMessagingCompat.ts#L38

@zwu52
Copy link
Member Author

zwu52 commented May 19, 2021

right. Good catch!

@zwu52 zwu52 requested a review from Feiyang1 May 19, 2021 20:06
Copy link
Member

@Feiyang1 Feiyang1 left a comment

Choose a reason for hiding this comment

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

@zwu52 zwu52 requested a review from Feiyang1 May 20, 2021 21:48
@zwu52 zwu52 merged commit a263827 into master May 21, 2021
@zwu52 zwu52 deleted the fix_compat branch May 21, 2021 00:24
@firebase firebase locked and limited conversation to collaborators Jun 20, 2021
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants