Skip to content

fix(mosaic): refetch the switcher trigger badge when the callback changes - #11063

Merged
alexcarpenter merged 1 commit into
mainfrom
carp/mosaic-trigger-badge-refetch
Dec 1, 2026
Merged

alexcarpenter merged 1 commit into
mainfrom
carp/mosaic-trigger-badge-refetch

Conversation

@alexcarpenter

Copy link
Copy Markdown
Member

Description

The switcher trigger badge did not update when the triggerBadge callback changed. #10456 (released in @clerk/mosaic 0.1.14) removed the callback from the badge request's useMemo deps to stop a flicker, so a new callback for the same kind, id and session never requested the badge again. For example, going from a callback that returns null to one that returns a plan left the trigger without a badge.

The request is keyed on the callback again. The flicker #10456 fixed came from hiding the badge while any request was pending. The controller now tags each result with the kind, id and session it was fetched for and shows the badge only when they match the current ones:

  • A new callback for the same kind, id and session keeps the last badge visible until the new one resolves, then swaps it.
  • Switching kind, id or session hides the badge right away, so another organization or account is never labelled with the wrong plan.

An inline callback requests the badge again on each render of the parent, but the badge stays mounted. The changeset recommends useCallback.

Two feature tests cover the refetch and the kept badge. The existing inline-callback test now expects the second request and still checks that the badge never unmounts.

Before

The pre-#10456 approach (callback in the deps, badge hidden while pending), Swingset Switcher → custom trigger badge, opening and closing three times. The trigger loses its badge and narrows on each open and close:

before-open-close.mp4

10× slow motion of the first open and close:

before-open-close-10x-slow.mp4

After

after-open-close.mp4

10× slow motion:

after-open-close-10x-slow.mp4

Checklist

  • pnpm test runs as expected.
  • pnpm build runs as expected.
  • (If applicable) JSDoc comments have been added or updated for any package exports
  • (If applicable) Documentation has been updated

Type of change

  • 🐛 Bug fix
  • 🌟 New feature
  • 🔨 Breaking change
  • 📖 Refactoring / dependency upgrade / documentation
  • other:

@vercel

vercel Bot commented Dec 1, 2026 •

Copy link
Copy Markdown

The latest updates on your projects. Learn more about Vercel for GitHub.

Project Deployment Actions Updated
clerk-js-sandbox Ready Ready Preview Dec 1, 2026 3:20pm UTC
mosaic-docs Ready Ready Preview Dec 1, 2026 3:20pm UTC
swingset Ready Ready Preview Dec 1, 2026 3:20pm UTC

Request Review

@changeset-bot

changeset-bot Bot commented Dec 1, 2026

Copy link
Copy Markdown

🦋 Changeset detected

Latest commit: b4dc9d9

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

This PR includes changesets to release 3 packages
Name Type
@clerk/mosaic Patch
@clerk/mosaic-docs Patch
@clerk/swingset 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

@coderabbitai

coderabbitai Bot commented Dec 1, 2026 •

Copy link
Copy Markdown
Contributor

Explain Change →

No actionable comments were generated in the recent review.

Walkthrough

The switcher trigger controller now associates each badge request and result with the current scope. It displays a result only when its scope matches the current scope. Tests cover callback updates, badge visibility while a replacement request is pending, and inline callback invocations after rerender. A patch changeset documents the update.

Estimated code review effort: 2 (Simple) | ~10 minutes

Possibly related PRs

  • clerk/javascript#10456: Updates the same badge-request logic by changing how callback identity and scope affect requests.

Suggested reviewers: dstaley, austincalvelage

Merge Risk: Minimal · up to b4dc9

This fixes the switcher trigger badge so it updates when the triggerBadge callback changes, and it keeps the badge visible while a replacement request is pending. No merge-blocking issues were found.

Pre-merge checks: Passed 4

Check name Status Explanation
Title check Passed The title names the change: the switcher trigger badge is refetched when the triggerBadge callback changes. The change set matches this. The title is specific and uses the conventional fix(mosaic) pre…
Description check Passed The description states the bug, the cause (#10456 removed the callback from the useMemo deps), and the fix (requests keyed on the callback again, results tagged with kind, id and session). It also lis…
Linked Issues check Passed Check skipped because no linked issues were found for this pull request.
Out of Scope Changes check Passed Check skipped because no linked issues were found for this pull request.
Full details: Title check

Explanation

The title names the change: the switcher trigger badge is refetched when the triggerBadge callback changes. The change set matches this. The title is specific and uses the conventional fix(mosaic) prefix.

Full details: Description check

Explanation

The description states the bug, the cause (#10456 removed the callback from the useMemo deps), and the fix (requests keyed on the callback again, results tagged with kind, id and session). It also lists the added feature tests and the changeset recommendation for useCallback. It is related to the changeset.

  • Autofix · Keep fixing CodeRabbit findings and required CI, and resolving merge conflicts

Warning

Linked repositories: This review skipped 6 repositories. Cross-repository analysis may be incomplete. Check linked repository access and settings.

Recent review info

Run configuration

Commits

Reviewing files that changed from the base of the PR and between 74fc74b and b4dc9d9.

Files selected for processing: 3

  • .changeset/mosaic-trigger-badge-refetch.md
  • packages/mosaic/src/features/switcher/__tests__/switcher.feature.test.tsx
  • packages/mosaic/src/features/switcher/switcher-trigger.controller.ts
Linked repositories identified

CodeRabbit considers these linked repositories for cross-repo context during reviews:

Included review availability: This review used your included allowance. 0 included reviews remain after this review. Your included PR review attempts over the past 7 days set your current allowance at 5 reviews per hour.

@blacksmith-sh

blacksmith-sh Bot commented Dec 1, 2026 •

Copy link
Copy Markdown

Matches New callback for the same org shows its badge

Head: the Pro plan badge appears after swapping callbacks (2 calls). Base: callback not called again and the trigger stays bare.

Before · Recording

Recording

Watch full video · Original footage · 0:00 Callback returns null · 0:01 Swap to a Pro plan callback

After · Recording

Recording

Watch full video · Original footage · 0:00 Callback returns null · 0:01 Swap to a Pro plan callback

Also checked · 4 match

Matches Previous badge stays until the new callback resolves
Matches Switching organization hides the old badge at once
Matches Inline callback refetches but badge never unmounts
Matches Switcher feature tests pass

Proof on b4dc9d98 · mocked: Clerk Frontend API (MSW stub in src/tests/feature/fake-fapi.ts seeds a signed-in user with two o...) · Did Proof get it right? Yes · No

View full Proof report · React 👎 or comment @codesmith dismiss this proof to dismiss

@pkg-pr-new

pkg-pr-new Bot commented Dec 1, 2026

Copy link
Copy Markdown

Open in StackBlitz

@clerk/astro

npm i https://pkg.pr.new/@clerk/astro@11063

@clerk/backend

npm i https://pkg.pr.new/@clerk/backend@11063

@clerk/chrome-extension

npm i https://pkg.pr.new/@clerk/chrome-extension@11063

@clerk/clerk-js

npm i https://pkg.pr.new/@clerk/clerk-js@11063

@clerk/electron

npm i https://pkg.pr.new/@clerk/electron@11063

@clerk/electron-passkeys

npm i https://pkg.pr.new/@clerk/electron-passkeys@11063

@clerk/eslint-plugin

npm i https://pkg.pr.new/@clerk/eslint-plugin@11063

@clerk/expo

npm i https://pkg.pr.new/@clerk/expo@11063

@clerk/expo-biometrics

npm i https://pkg.pr.new/@clerk/expo-biometrics@11063

@clerk/expo-google-signin

npm i https://pkg.pr.new/@clerk/expo-google-signin@11063

@clerk/expo-native-components

npm i https://pkg.pr.new/@clerk/expo-native-components@11063

@clerk/expo-passkeys

npm i https://pkg.pr.new/@clerk/expo-passkeys@11063

@clerk/express

npm i https://pkg.pr.new/@clerk/express@11063

@clerk/fastify

npm i https://pkg.pr.new/@clerk/fastify@11063

@clerk/hono

npm i https://pkg.pr.new/@clerk/hono@11063

@clerk/localizations

npm i https://pkg.pr.new/@clerk/localizations@11063

@clerk/mosaic

npm i https://pkg.pr.new/@clerk/mosaic@11063

@clerk/nextjs

npm i https://pkg.pr.new/@clerk/nextjs@11063

@clerk/nuxt

npm i https://pkg.pr.new/@clerk/nuxt@11063

@clerk/react

npm i https://pkg.pr.new/@clerk/react@11063

@clerk/react-router

npm i https://pkg.pr.new/@clerk/react-router@11063

@clerk/shared

npm i https://pkg.pr.new/@clerk/shared@11063

@clerk/tanstack-react-start

npm i https://pkg.pr.new/@clerk/tanstack-react-start@11063

@clerk/testing

npm i https://pkg.pr.new/@clerk/testing@11063

@clerk/ui

npm i https://pkg.pr.new/@clerk/ui@11063

@clerk/upgrade

npm i https://pkg.pr.new/@clerk/upgrade@11063

@clerk/vue

npm i https://pkg.pr.new/@clerk/vue@11063

commit: b4dc9d9

@alexcarpenter
alexcarpenter merged commit 49ff25d into main Dec 1, 2026
61 checks passed
@alexcarpenter
alexcarpenter deleted the carp/mosaic-trigger-badge-refetch branch December 1, 2026 15:30

This branch was successfully deployed

2 active deployments
Preview – swingset — b4dc9d98 Deployed Dec 1, 2026 by vercel[bot]
Preview – clerk-js-sandbox — b4dc9d98 Deployed Dec 1, 2026 by vercel[bot]
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants