Skip to content

refactor(shared,clerk-js,react): move QueryClient ownership into @clerk/shared#8434

Open
jacekradko wants to merge 11 commits intomainfrom
jacek/clerk-rq-invert-ownership
Open

refactor(shared,clerk-js,react): move QueryClient ownership into @clerk/shared#8434
jacekradko wants to merge 11 commits intomainfrom
jacek/clerk-rq-invert-ownership

Conversation

@jacekradko
Copy link
Copy Markdown
Member

@jacekradko jacekradko commented Apr 30, 2026

Summary

  • Moves the clerk-rq QueryClient from @clerk/clerk-js into @clerk/shared. Both the QueryObserver and the Query objects it observes now resolve to a single @tanstack/query-core instance.
  • Removes the undocumented clerk.__internal_queryClient getter from both @clerk/clerk-js and @clerk/react's IsomorphicClerk, plus the dynamic query-core import and queryClientStatus event.
  • Drops @tanstack/query-core from @clerk/clerk-js's dependencies (still a dep of @clerk/shared).

Why

#8432 patched the symptom of #8428 by republishing the CDN bundle so its embedded query-core matches what consumers' @clerk/shared resolves to. That fix is correct but structural — every future query-core release that adds an Observer → Query method call could re-trigger the same crash class until both sides are forced to share one resolution.

This PR removes the cross-bundle contract entirely. The QueryClient is owned by an internal singleton in @clerk/shared, lazily instantiated on the browser only. Both the QueryObserver (constructor lives in @clerk/shared) and the Query objects (created via client.getQueryCache().build(...)) now come from one resolution — the gap #8428 exploited can no longer exist.

Key insight: clerk-js never mutated the QueryClient — every setQueryData / invalidateQueries / removeQueries call already lives in @clerk/shared hooks. So no push API back into clerk-js is needed; clerk-js simply stops creating the client.

Behavior changes

  • clerk.__internal_queryClient removed. Undocumented (leading underscore + @ts-expect-error at every call site), but technically observable. No code in this monorepo reaches for it outside the call sites I removed; possible external consumers should now construct their own QueryClient if they need one.
  • SSR safety preserved. getClerkQueryClient() returns undefined server-side, so per-request renders never share a cache across requests. Hooks fall back to the same proxy mock + synthetic pending state that existed before.
  • queryClientStatus event removed. It was emitted once when clerk-js's lazy query-core import resolved; with the singleton synchronously available on the browser there's nothing to signal. No code outside the removed listeners consumed it.

Test plan

  • pnpm --filter @clerk/shared test — 1069/1069
  • pnpm --filter @clerk/clerk-js test — 688/688
  • pnpm --filter @clerk/ui test — 1681/1681 (incl. SubscriptionDetails / Checkout, the regression-prone billing UI tests)
  • pnpm --filter @clerk/clerk-js build — clean, no query-core-vendors_*.js chunk in dist (confirms the dep was actually dropped)
  • pnpm --filter @clerk/shared build

Stacked on #8432 — base will be main once #8432 lands.

@vercel
Copy link
Copy Markdown

vercel Bot commented Apr 30, 2026

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

Project Deployment Actions Updated (UTC)
clerk-js-sandbox Ready Ready Preview, Comment May 2, 2026 4:29pm

Request Review

@changeset-bot
Copy link
Copy Markdown

changeset-bot Bot commented Apr 30, 2026

🦋 Changeset detected

Latest commit: 626d5f5

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

This PR includes changesets to release 20 packages
Name Type
@clerk/shared Patch
@clerk/clerk-js Patch
@clerk/react Patch
@clerk/astro Patch
@clerk/backend Patch
@clerk/chrome-extension Patch
@clerk/expo-passkeys Patch
@clerk/expo Patch
@clerk/express Patch
@clerk/fastify Patch
@clerk/hono Patch
@clerk/localizations Patch
@clerk/msw Patch
@clerk/nextjs Patch
@clerk/nuxt Patch
@clerk/react-router Patch
@clerk/tanstack-react-start Patch
@clerk/testing Patch
@clerk/ui Patch
@clerk/vue 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

Base automatically changed from jacek/bump-query-core-cdn to main April 30, 2026 17:55
…-ownership

# Conflicts:
#	packages/clerk-js/package.json
#	packages/shared/package.json
#	pnpm-lock.yaml
@coderabbitai
Copy link
Copy Markdown
Contributor

coderabbitai Bot commented Apr 30, 2026

Note

Reviews paused

It looks like this branch is under active development. To avoid overwhelming you with review comments due to an influx of new commits, CodeRabbit has automatically paused this review. You can configure this behavior by changing the reviews.auto_review.auto_pause_after_reviewed_commits setting.

Use the following commands to manage reviews:

  • @coderabbitai resume to resume automatic reviews.
  • @coderabbitai review to trigger a single review.

Use the checkboxes below for quick actions:

  • ▶️ Resume reviews
  • 🔍 Trigger review
📝 Walkthrough

Walkthrough

QueryClient ownership for clerk-rq is moved out of @clerk/clerk-js into a new singleton manager in @clerk/shared that lazily creates a browser-only QueryClient and exposes test helpers and a public accessor. The undocumented __internal_queryClient getters were removed from clerk-js and IsomorphicClerk in react. Tests and mock helpers across clerk-js, shared, react, and ui were updated to use the shared helpers. @tanstack/query-core was removed from clerk-js runtime deps and its forced vendor chunk/specific bundlewatch entry were removed; some UI bundle size thresholds were adjusted. New re-exports added from @clerk/shared/react.

Estimated code review effort

🎯 4 (Complex) | ⏱️ ~45 minutes

🚥 Pre-merge checks | ✅ 4 | ❌ 1

❌ Failed checks (1 warning)

Check name Status Explanation Resolution
Docstring Coverage ⚠️ Warning Docstring coverage is 66.67% which is insufficient. The required threshold is 80.00%. Write docstrings for the functions missing them to satisfy the coverage threshold.
✅ Passed checks (4 passed)
Check name Status Explanation
Title check ✅ Passed The title accurately summarizes the main refactoring: moving QueryClient ownership from @clerk/clerk-js to @clerk/shared, which is the central architectural change in this PR.
Description check ✅ Passed The description is directly related to the changeset, clearly explaining the motivation (eliminating cross-bundle API mismatch), implementation approach (singleton in @clerk/shared), and behavioral changes including preserved SSR safety.
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.

✏️ Tip: You can configure your own custom pre-merge checks in the settings.


Comment @coderabbitai help to get the list of available commands and usage tips.

@pkg-pr-new
Copy link
Copy Markdown

pkg-pr-new Bot commented Apr 30, 2026

Open in StackBlitz

@clerk/astro

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

@clerk/backend

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

@clerk/chrome-extension

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

@clerk/clerk-js

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

@clerk/dev-cli

npm i https://pkg.pr.new/@clerk/dev-cli@8434

@clerk/expo

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

@clerk/expo-passkeys

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

@clerk/express

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

@clerk/fastify

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

@clerk/hono

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

@clerk/localizations

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

@clerk/nextjs

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

@clerk/nuxt

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

@clerk/react

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

@clerk/react-router

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

@clerk/shared

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

@clerk/tanstack-react-start

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

@clerk/testing

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

@clerk/ui

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

@clerk/upgrade

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

@clerk/vue

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

commit: 626d5f5

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant