Skip to content

Implement register() and FID-based registration with onRegistered / onUnregistered#9714

Merged
zwu52 merged 7 commits intofeat/messaging-api-seriesfrom
feat/messaging-phase2-concurrent-registration
Mar 24, 2026
Merged

Implement register() and FID-based registration with onRegistered / onUnregistered#9714
zwu52 merged 7 commits intofeat/messaging-api-seriesfrom
feat/messaging-phase2-concurrent-registration

Conversation

@zwu52
Copy link
Copy Markdown
Member

@zwu52 zwu52 commented Mar 11, 2026

Implements Phase 2 of FCM Web modernization: a new register() API that links the app to its Firebase Installation ID (FID) and delivers it via the onRegistered callback, plus onUnregistered for when a FID is deactivated. This supports moving from legacy FCM tokens to FID as the primary send target.

register(messaging, options?) ensures VAPID and service worker are set, gets the FID from Installations, and invokes onRegistered with it (same options as getToken). When register() is called multiple times, onRegistered is only invoked when the FID changes from the last notified value (or on first call). The “get FID → compare → notify” step is serialized so concurrent register() calls do not trigger duplicate callbacks for the same FID.

New surface: onRegistered(messaging, nextOrObserver) and onUnregistered(messaging, nextOrObserver) for subscribing to FID delivery and deactivation. Unit tests cover options passthrough, observer vs function handler, FID source, and the dedupe and three-call FID-change behavior. All 78 messaging tests pass.

@zwu52 zwu52 requested review from a team as code owners March 11, 2026 02:49
@gemini-code-assist
Copy link
Copy Markdown
Contributor

Warning

You have reached your daily quota limit. Please wait up to 24 hours and I will start processing your requests again!

@changeset-bot
Copy link
Copy Markdown

changeset-bot Bot commented Mar 11, 2026

⚠️ No Changeset found

Latest commit: aa58210

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

zwu52 added 2 commits March 10, 2026 19:51
- Restore copyright year to 2020; add JSDoc for FID-dedupe behavior
- Serialize get FID + compare + notify to avoid duplicate callback on concurrent register()
- Add lastNotifiedFid assertion and three-call FID-change test

Made-with: Cursor
@zwu52 zwu52 force-pushed the feat/messaging-phase2-concurrent-registration branch from 182879a to 39f546b Compare March 11, 2026 02:52
@zwu52 zwu52 requested a review from Doris-Ge March 11, 2026 17:21
Comment thread packages/messaging/src/api/register.ts
Comment thread packages/messaging/src/api/register.ts
Comment thread packages/messaging/src/api/register.ts
Comment thread packages/messaging/src/api/register.test.ts Outdated
@zwu52 zwu52 requested a review from Doris-Ge March 19, 2026 19:07
Comment thread packages/messaging/src/internals/register-fid.ts Outdated
Comment thread packages/messaging/src/internals/requests.ts Outdated
Comment thread packages/messaging/src/api/register.ts Outdated
Comment thread packages/messaging/src/api/register.ts Outdated
Comment thread packages/messaging/src/api/register.test.ts Outdated
Comment thread packages/messaging/src/api/register.ts Outdated
Comment thread packages/messaging/src/api.ts Outdated
Comment thread packages/messaging/src/api.ts Outdated
Comment thread packages/messaging/src/api/register.ts Outdated
Comment thread packages/messaging/src/internals/requests.ts
@zwu52 zwu52 requested a review from Doris-Ge March 20, 2026 21:04
Comment thread packages/messaging/src/util/errors.ts Outdated
Comment thread packages/messaging/src/internals/requests.ts Outdated
Comment thread packages/messaging/src/internals/register-fid.ts Outdated
Comment thread packages/messaging/src/helpers/migrate-old-database.ts Outdated
Comment thread packages/messaging/src/api/register.ts
@zwu52 zwu52 merged commit 155fc84 into feat/messaging-api-series Mar 24, 2026
29 of 32 checks passed
@zwu52 zwu52 deleted the feat/messaging-phase2-concurrent-registration branch March 24, 2026 18:45
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.

4 participants