re-register on FID change #9759
Conversation
…Change - Subscribe to Firebase Installations onIdChange when creating window messaging - On FID change, call register() when onRegistered is set so FCM registration and onRegistered run for the new ID - Unsubscribe in MessagingService._delete() - Add unit tests for subscribeFidChangeRegistration Made-with: Cursor
|
Summary of ChangesHello, I'm Gemini Code Assist1! I'm currently reviewing this pull request and will post my feedback shortly. In the meantime, here's a summary to help you and other reviewers quickly get up to speed! This pull request significantly enhances the Firebase Messaging SDK by introducing a robust mechanism for automatically updating Firebase Cloud Messaging (FCM) registration when the underlying Firebase Installation ID (FID) changes. By integrating with Firebase Installations' onIdChange event, the SDK now proactively re-registers the FCM token, ensuring that applications always maintain a valid and up-to-date token without requiring developers to implement manual polling or refresh logic. This improves the reliability of message delivery and simplifies the developer experience. Highlights
🧠 New Feature in Public Preview: You can now enable Memory to help Gemini Code Assist learn from your team's feedback. This makes future code reviews more consistent and personalized to your project's style. Click here to enable Memory in your admin console. Using Gemini Code AssistThe full guide for Gemini Code Assist can be found on our documentation page, here are some quick tips. Invoking Gemini You can request assistance from Gemini at any point by creating a comment using either
Customization To customize Gemini Code Assist for GitHub experience, repository maintainers can create a configuration file and/or provide a custom code review style guide (such as PEP-8 for Python) by creating and adding files to a Limitations & Feedback Gemini Code Assist may make mistakes. Please leave feedback on any instances where its feedback is incorrect or counter productive. You can react with 👍 and 👎 on @gemini-code-assist comments. If you're interested in giving your feedback about your experience with Gemini Code Assist for GitHub and other Google products, sign up here. Footnotes
|
Added a TODO comment to refresh the VAPID key weekly.
There was a problem hiding this comment.
Code Review
This pull request introduces a new mechanism to handle Firebase Installation ID (FID) changes by re-registering FCM tokens. A new helper function, subscribeFidChangeRegistration, is added to listen for FID changes and re-invoke the register function if an onRegisteredHandler is present. The MessagingService is updated to store and clean up the FID change unsubscribe function during service deletion. New tests have been added for this functionality. The review comments suggest improving the test setup in fid-change-registration.test.ts by providing a more robust mock object for installationsApi.Installations instead of casting an empty object, to prevent brittleness.
|
|
||
| _delete(): Promise<void> { | ||
| if (this._fidChangeUnsubscribe) { | ||
| this._fidChangeUnsubscribe(); |
There was a problem hiding this comment.
Why do we need to call this function before setting it to null?
There was a problem hiding this comment.
Ditto above, this callback is only called when messaging instance is bond to be "deleted" (end of the app lifecycle)
| } | ||
| ) as Stub<typeof installationsApi.onIdChange>; | ||
|
|
||
| registerStub = stub(registerModule, 'register').resolves() as Stub< |
There was a problem hiding this comment.
Is there a way that we can test the whole flow without using a stub? For example, if the fid changes, onRegistered will be invoked with the new fid.
…register - Use mutable installations getId and stub requestCreateRegistration only - Assert onRegistered receives the rotated FID; cover unsubscribe-on-teardown - Add TODO for periodic refresh in register path Made-with: Cursor
efa5bf0 to
80e9729
Compare
Summary
When the Firebase Installation ID (FID) changes, the Messaging SDK now listens via Firebase Installations
onIdChange(including cross-tab updates) and callsregister()when anonRegisteredhandler is set. That re-runs FCM FID registration and delivers the new FID throughonRegistered, without requiring the app to pollgetId().Implementation
subscribeFidChangeRegistration()usesonIdChangefrom@firebase/installations.MessagingServicefactory; unsubscribe stored onMessagingServiceand cleared in_delete().onRegisteredhandler is registered, the FID-change path does not callregister()(avoidsinvalid-on-registered-handler).register()in this path are swallowed to avoid unhandled rejections (e.g. revoked permission).