Skip to content

feat(react-query): compose query modes and tree-shake client operations on v6 - #12714

Closed
manudeli wants to merge 12 commits into
query-v6from
experiment/v6-react-query-no-core
Closed

manudeli wants to merge 12 commits into
query-v6from
experiment/v6-react-query-no-core

Conversation

@manudeli

@manudeli manudeli commented Nov 27, 2026 •

Copy link
Copy Markdown
Collaborator

🎯 Changes

I want a screen that reads one query to pay for the code that read needs. This draft adds @tanstack/react-query-pluggable, an ESM adapter for React 19. It shares retry, cancellation, garbage collection, state helpers and environment managers with @tanstack/query-core. Optional observers, cache operations and polling enter the bundle through the imports that use them. The comparison uses the unchanged @tanstack/react-query from the query-v6 base.

ESM gives bundlers a static import graph, but methods on a constructed class can keep features reachable. I’m comfortable asking users to migrate to separate named imports when the app actually drops those implementations. I expect TypeScript and AI-assisted development to make more distributed APIs easier to find and migrate. That is a design assumption. The measurements below test the payload savings.

One hook, four query modes

Create a QueryClient and pass it to QueryClientProvider from the same package. A caller can choose how each useQuery invocation reads its data. Here post contains a query key and fetch function. pages also supplies initialPageParam and getNextPageParam.

Consumer @tanstack/react-query @tanstack/react-query-pluggable
Single query with a pending result useQuery(post) useQuery(query(post))
Single query under a Suspense boundary useSuspenseQuery(post) useQuery(suspenseQuery(post))
Paginated query with a pending result useInfiniteQuery(pages) useQuery(infiniteQuery(pages))
Paginated query under a Suspense boundary useSuspenseInfiniteQuery(pages) useQuery(suspenseQuery(infiniteQuery(pages)))

query is the same JavaScript function as queryOptions. useQuery(post) still works. The paginated result exposes data.pages, hasNextPage and fetchNextPage. Wrapping the options in suspenseQuery lets the nearest Suspense boundary handle an uncached read and the nearest error boundary handle a failed fetch without cached data. The dedicated hooks remain available. Both readers of the same query key use the same cached data.

Move client operations to named imports

QueryClient holds the caches, defaults and lifecycle state. Every operation on that client is a named export with the client as its first argument. Creating a client for useQuery can therefore leave out imperative fetching, writes and bulk invalidation.

Before, on query-v6

import { QueryClient } from '@tanstack/react-query'

const client = new QueryClient()
const post = await client.query(postOptions)
const cached = client.getQueryData(postOptions.queryKey)
client.setQueryData(postOptions.queryKey, updatedPost)
await client.infiniteQuery(pageOptions)
await client.invalidateQueries({ queryKey: ['posts'] })
const unsubscribe = client.getQueryCache().subscribe(onQueryEvent)

With the pluggable adapter

import {
  QueryClient, fetchQuery, fetchInfiniteQuery, getQueryCache,
  getQueryData, invalidateQueries, setQueryData,
} from '@tanstack/react-query-pluggable'

const client = new QueryClient()
const post = await fetchQuery(client, postOptions)
const cached = getQueryData(client, postOptions.queryKey)
setQueryData(client, postOptions.queryKey, updatedPost)
await fetchInfiniteQuery(client, pageOptions)
await invalidateQueries(client, { queryKey: ['posts'] })
const unsubscribe = getQueryCache(client).subscribe(onQueryEvent)

Defaults follow the same convention, for example setQueryDefaults(client, key, options). The provider handles mount and unmount. Integrations that manage a client directly use mountQueryClient(client), unmountQueryClient(client) and clearQueryClient(client).

Cache objects keep their own methods. getMutationCache(client).subscribe(listener) creates a cache on first access or returns the constructor-supplied cache. useMutation acquires the same cache automatically. The stock @tanstack/query-persist-client-core subscription calls client.getQueryCache() and client.getMutationCache() on the instance. A persistence integration for this adapter must use the named accessors and the adapter's hydrate and dehydrate.

Import option behavior where it is used

Feature v6 option Pluggable option
Poll every three seconds refetchInterval: 3000 refetchInterval: refetchInterval(3000)
Select a title for one observer select: (post) => post.title select: [select, (post) => post.title]
Keep the previous page while fetching placeholderData: keepPreviousData placeholderData: placeholderData(keepPreviousData)
Serialize mutations for one scope scope: { id: 'orders' } scope: serialScope('orders')

The tuple preserves inline selector inference. An already typed selector can use select: select(getTitle). Mutations with the same scope ID run in order within a cache, including after dehydration and hydration. The three option factories (queryOptions, infiniteQueryOptions, and mutationOptions) specialize their TypeScript signatures and share one JavaScript identity function.

What reaches the browser?

Gzipped Query runtime

Workload React Query v6 React Query Pluggable Change vs v6
Read-only list 9,159 B 7,277 B -1,882 B (-20.55%)
Paginated bookmarks 10,636 B 9,687 B -949 B (-8.92%)
Selection, serial bookmarks and invalidation 10,320 B 9,685 B -635 B (-6.15%)
Polling 9,777 B 8,559 B -1,218 B (-12.46%)

For the read-only app, whole-app gzip goes from 76,925 B to 75,107 B (−2.36%). The query-only build excludes MutationCache, the infinite observer, Suspense and unreferenced imperative operations. The bookmark apps include the mutation implementation.

Each push builds four production apps against both packages. The primary percentage uses the compressed Query runtime for that workload, including all retained query-core modules. The same comment also measures the whole app with React and React DOM. The build checks the isolated chunk against the module and export graph of the deployable app. Chromium exercises all eight apps, including real Suspense fallback, pagination, polling and mutation flows. Bundle comparison and interactive treemaps

The stock React package’s separate Brotli size-limit measurement is 12,703 → 12,714 B for the full entry (+11 B, +0.09%) and 8,391 → 8,396 B for the minimal entry (+5 B, +0.06%). Preview size-limit report

✅ Checklist

  • Followed the contributing guide.
  • Ran pnpm test and pnpm run test:pr on this revision. Ten Next.js example builds stopped on their first run for an upgrade notice and passed on retry. Nx reported 656 successful tasks in both final commands. The GitHub Test job passed.
  • I have followed the AI contribution policy and fully understand the code in this pull request, including any code generated with AI assistance.

🚀 Release Impact

  • This change affects published code, and I have included a changeset for the experimental adapter and the new core export.
  • This change is docs/CI/dev-only (no release).

@changeset-bot

changeset-bot Bot commented Nov 27, 2026 •

Copy link
Copy Markdown

🦋 Changeset detected

Latest commit: 8a21fac

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

This PR includes changesets to release 26 packages
Name Type
@tanstack/query-core Minor
@tanstack/react-query-pluggable Minor
@tanstack/angular-query Minor
@tanstack/lit-query Patch
@tanstack/preact-query Minor
@tanstack/query-async-storage-persister Minor
@tanstack/query-broadcast-client-experimental Minor
@tanstack/query-devtools Minor
@tanstack/query-persist-client-core Minor
@tanstack/react-query Minor
@tanstack/solid-query Minor
@tanstack/svelte-query Patch
@tanstack/vue-query Minor
@tanstack/angular-query-devtools Minor
@tanstack/angular-query-persist-client Minor
@tanstack/preact-query-devtools Minor
@tanstack/preact-query-persist-client Minor
@tanstack/react-query-devtools Minor
@tanstack/solid-query-devtools Minor
@tanstack/svelte-query-devtools Patch
@tanstack/vue-query-devtools Patch
@tanstack/react-query-persist-client Minor
@tanstack/solid-query-persist-client Minor
@tanstack/svelte-query-persist-client Patch
@tanstack/react-query-next-experimental Minor
@tanstack/eslint-plugin-query Minor

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 Nov 27, 2026

Copy link
Copy Markdown
Contributor

Important

Draft PR not reviewed

Draft PRs are not automatically reviewed by default.

  • Trigger a manual review

To automatically review draft PRs, update your CodeRabbit configuration:

reviews:
  auto_review:
    drafts: true
  • Autofix · Keep fixing CodeRabbit findings and required CI, and resolving merge conflicts

Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

Share

@nx-cloud

nx-cloud Bot commented Nov 27, 2026 •

Copy link
Copy Markdown

View your CI Pipeline Execution ↗ for commit 8a21fac

Command Status Duration Result
nx affected --targets=test:sherif,test:knip,tes... ✅ Succeeded 9m 21s View ↗
nx run-many --target=build --exclude=examples/*... ✅ Succeeded 1s View ↗

☁️ Nx Cloud last updated this comment at 2026-11-27 14:11:44 UTC

@github-actions

github-actions Bot commented Nov 27, 2026 •

Copy link
Copy Markdown
Contributor

🚀 Changeset Version Preview

24 package(s) bumped directly, 2 bumped as dependents.

🟥 Major bumps

Package Version Reason
@tanstack/angular-query 5.108.4 → 6.0.0 Changeset
@tanstack/angular-query-devtools 5.108.4 → 6.0.0 Changeset
@tanstack/eslint-plugin-query 5.108.4 → 6.0.0 Changeset
@tanstack/lit-query 0.2.44 → 1.0.0 Changeset
@tanstack/preact-query 5.108.4 → 6.0.0 Changeset
@tanstack/preact-query-devtools 5.108.4 → 6.0.0 Changeset
@tanstack/preact-query-persist-client 5.108.4 → 6.0.0 Changeset
@tanstack/query-async-storage-persister 5.108.4 → 6.0.0 Changeset
@tanstack/query-broadcast-client-experimental 5.108.4 → 6.0.0 Changeset
@tanstack/query-core 5.108.4 → 6.0.0 Changeset
@tanstack/query-devtools 5.108.4 → 6.0.0 Changeset
@tanstack/query-persist-client-core 5.108.4 → 6.0.0 Changeset
@tanstack/react-query 5.108.4 → 6.0.0 Changeset
@tanstack/react-query-devtools 5.108.4 → 6.0.0 Changeset
@tanstack/react-query-next-experimental 5.108.4 → 6.0.0 Changeset
@tanstack/react-query-persist-client 5.108.4 → 6.0.0 Changeset
@tanstack/solid-query 5.108.4 → 6.0.0 Changeset
@tanstack/solid-query-devtools 5.108.4 → 6.0.0 Changeset
@tanstack/solid-query-persist-client 5.108.4 → 6.0.0 Changeset
@tanstack/svelte-query 6.4.7 → 7.0.0 Changeset
@tanstack/svelte-query-devtools 6.4.7 → 7.0.0 Changeset
@tanstack/vue-query 5.108.4 → 6.0.0 Changeset
@tanstack/vue-query-devtools 6.4.7 → 7.0.0 Changeset
@tanstack/angular-query-persist-client 5.108.4 → 6.0.0 Dependent
@tanstack/svelte-query-persist-client 6.4.7 → 7.0.0 Dependent

🟨 Minor bumps

Package Version Reason
@tanstack/react-query-pluggable 5.108.4 → 5.109.0 Changeset

@github-actions

github-actions Bot commented Nov 27, 2026 •

Copy link
Copy Markdown
Contributor

React Query bundle size

Gzipped Query runtime

Each row compares the Query JavaScript used by the same app. The change is measured against v6 for that row. Negative values mean fewer bytes.

Workload React Query v6 React Query Pluggable Change vs v6
Read-only list 9,159 B 7,277 B -1,882 B (-20.55%)
Paginated bookmarks 10,636 B 9,687 B -949 B (-8.92%)
Selection, serial bookmarks and invalidation 10,320 B 9,685 B -635 B (-6.15%)
Polling 9,777 B 8,559 B -1,218 B (-12.46%)

The pluggable read-only list retains the query client, cache, query and observer. Its production build drops the Suspense builder and policy, mutation cache and observer, polling scheduler, infinite-query behavior, selection, placeholder data, serial scopes and bulk cache operations. Both bookmark apps retain the mutation cache and observer.

Baseline adapter and core at f467a6a061aca15e9d7e004bafe3d521180add88 (base checkout). Pluggable adapter, core and fixture at 8a21fac770b3d63a8fada1f272cd33df9eda89ff.

Query runtime sizes · minified JS, gzip and Brotli

The app entry drives tree-shaking. This build externalizes React and React DOM and groups the adapter and its retained query-core modules into one ESM chunk for each package. Each cell measures the isolated chunk directly.

Workload Package Minified JS Gzip Brotli
Read-only list @tanstack/react-query 29,272 B 9,159 B 8,374 B
Read-only list @tanstack/react-query-pluggable 22,088 B
-7,184 B (-24.54%)
7,277 B
-1,882 B (-20.55%)
6,673 B
-1,701 B (-20.31%)
Paginated bookmarks @tanstack/react-query 36,362 B 10,636 B 9,712 B
Paginated bookmarks @tanstack/react-query-pluggable 32,136 B
-4,226 B (-11.62%)
9,687 B
-949 B (-8.92%)
8,883 B
-829 B (-8.54%)
Selection, serial bookmarks and invalidation @tanstack/react-query 35,099 B 10,320 B 9,429 B
Selection, serial bookmarks and invalidation @tanstack/react-query-pluggable 32,123 B
-2,976 B (-8.48%)
9,685 B
-635 B (-6.15%)
8,881 B
-548 B (-5.81%)
Polling @tanstack/react-query 31,464 B 9,777 B 8,948 B
Polling @tanstack/react-query-pluggable 26,031 B
-5,433 B (-17.27%)
8,559 B
-1,218 B (-12.46%)
7,860 B
-1,088 B (-12.16%)

Largest modules in the read-only pluggable chunk, by rendered size before minification: react-query-pluggable/build/runtime/queryObserver.js, react-query-pluggable/build/runtime/query.js, query-core/build/utils.js, query-core/build/retryer.js, react-query-pluggable/build/runtime/queryClient.js.

Whole production app sizes · minified JS, gzip and Brotli

Each build includes the app, React, React DOM and Query. This measures the JavaScript delivered to the browser.

Workload Package Minified JS Gzip Brotli
Read-only list @tanstack/react-query 249,864 B 76,925 B 66,689 B
Read-only list @tanstack/react-query-pluggable 242,697 B
-7,167 B (-2.87%)
75,107 B
-1,818 B (-2.36%)
65,054 B
-1,635 B (-2.45%)
Paginated bookmarks @tanstack/react-query 257,561 B 78,593 B 68,214 B
Paginated bookmarks @tanstack/react-query-pluggable 253,393 B
-4,168 B (-1.62%)
77,675 B
-918 B (-1.17%)
67,363 B
-851 B (-1.25%)
Selection, serial bookmarks and invalidation @tanstack/react-query 256,671 B 78,435 B 68,042 B
Selection, serial bookmarks and invalidation @tanstack/react-query-pluggable 253,664 B
-3,007 B (-1.17%)
77,771 B
-664 B (-0.85%)
67,469 B
-573 B (-0.84%)
Polling @tanstack/react-query 252,901 B 77,753 B 67,430 B
Polling @tanstack/react-query-pluggable 247,618 B
-5,283 B (-2.09%)
76,600 B
-1,153 B (-1.48%)
66,352 B
-1,078 B (-1.60%)

All sizes are bytes. Each JavaScript chunk is compressed separately with gzip level 9 and Brotli quality 11, then summed.

Download the interactive bundle treemaps

@pkg-pr-new

pkg-pr-new Bot commented Nov 27, 2026 •

Copy link
Copy Markdown
More templates

@tanstack/angular-query

npm i https://pkg.pr.new/TanStack/query/@tanstack/angular-query@12714

@tanstack/angular-query-devtools

npm i https://pkg.pr.new/TanStack/query/@tanstack/angular-query-devtools@12714

@tanstack/angular-query-persist-client

npm i https://pkg.pr.new/TanStack/query/@tanstack/angular-query-persist-client@12714

@tanstack/eslint-plugin-query

npm i https://pkg.pr.new/TanStack/query/@tanstack/eslint-plugin-query@12714

@tanstack/lit-query

npm i https://pkg.pr.new/TanStack/query/@tanstack/lit-query@12714

@tanstack/preact-query

npm i https://pkg.pr.new/TanStack/query/@tanstack/preact-query@12714

@tanstack/preact-query-devtools

npm i https://pkg.pr.new/TanStack/query/@tanstack/preact-query-devtools@12714

@tanstack/preact-query-persist-client

npm i https://pkg.pr.new/TanStack/query/@tanstack/preact-query-persist-client@12714

@tanstack/query-async-storage-persister

npm i https://pkg.pr.new/TanStack/query/@tanstack/query-async-storage-persister@12714

@tanstack/query-broadcast-client-experimental

npm i https://pkg.pr.new/TanStack/query/@tanstack/query-broadcast-client-experimental@12714

@tanstack/query-core

npm i https://pkg.pr.new/TanStack/query/@tanstack/query-core@12714

@tanstack/query-devtools

npm i https://pkg.pr.new/TanStack/query/@tanstack/query-devtools@12714

@tanstack/query-persist-client-core

npm i https://pkg.pr.new/TanStack/query/@tanstack/query-persist-client-core@12714

@tanstack/react-query

npm i https://pkg.pr.new/TanStack/query/@tanstack/react-query@12714

@tanstack/react-query-devtools

npm i https://pkg.pr.new/TanStack/query/@tanstack/react-query-devtools@12714

@tanstack/react-query-next-experimental

npm i https://pkg.pr.new/TanStack/query/@tanstack/react-query-next-experimental@12714

@tanstack/react-query-persist-client

npm i https://pkg.pr.new/TanStack/query/@tanstack/react-query-persist-client@12714

@tanstack/react-query-pluggable

npm i https://pkg.pr.new/TanStack/query/@tanstack/react-query-pluggable@12714

@tanstack/solid-query

npm i https://pkg.pr.new/TanStack/query/@tanstack/solid-query@12714

@tanstack/solid-query-devtools

npm i https://pkg.pr.new/TanStack/query/@tanstack/solid-query-devtools@12714

@tanstack/solid-query-persist-client

npm i https://pkg.pr.new/TanStack/query/@tanstack/solid-query-persist-client@12714

@tanstack/svelte-query

npm i https://pkg.pr.new/TanStack/query/@tanstack/svelte-query@12714

@tanstack/svelte-query-devtools

npm i https://pkg.pr.new/TanStack/query/@tanstack/svelte-query-devtools@12714

@tanstack/svelte-query-persist-client

npm i https://pkg.pr.new/TanStack/query/@tanstack/svelte-query-persist-client@12714

@tanstack/vue-query

npm i https://pkg.pr.new/TanStack/query/@tanstack/vue-query@12714

@tanstack/vue-query-devtools

npm i https://pkg.pr.new/TanStack/query/@tanstack/vue-query-devtools@12714

commit: 8a21fac

@github-actions

github-actions Bot commented Nov 27, 2026 •

Copy link
Copy Markdown
Contributor

size-limit report 📦

Path Size
react full 12.42 KB (+0.09% 🔺)
react minimal 8.2 KB (+0.06% 🔺)

@socket-security

socket-security Bot commented Nov 27, 2026 •

Copy link
Copy Markdown

Review the following changes in direct dependencies. Learn more about Socket for GitHub.

Diff Package Supply Chain
Security
Vulnerability Quality Maintenance License
Added@​vitest/​ui@​5.0.5991007598100
Addedplaywright@​1.65.11001001009980
Added@​vitest/​browser-playwright@​5.0.51001008698100

View full report

@manudeli manudeli changed the title feat(react-query): compare standalone and pluggable ESM runtimes on v6 feat(react-query): compose query modes and tree-shake client operations on v6 Nov 27, 2026
@manudeli manudeli closed this Nov 27, 2026
@manudeli
manudeli deleted the experiment/v6-react-query-no-core branch November 27, 2026 14:18
@manudeli manudeli mentioned this pull request Nov 27, 2026
4 of 5 tasks
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.

1 participant