Skip to content
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
32 commits
Select commit Hold shift + click to select a range
ace4b63
feat(react-query): experiment with standalone and pluggable ESM runtimes
manudeli Nov 27, 2026
e5573d6
test(react-query): exercise all six measured apps in Chromium
manudeli Nov 27, 2026
b33f011
feat(react-query): opt into polling per query instead of per client
manudeli Nov 27, 2026
83a2748
perf(react-query): share one runtime identity across typed option hel…
manudeli Nov 27, 2026
ca32c29
refactor(react-query): import React runtime modules directly and drop…
manudeli Nov 27, 2026
0048eb5
Merge query-v6 and remove the obsolete timer helper from the React ru…
manudeli Nov 27, 2026
d6368a7
test(react-query): measure production bundles against the unchanged P…
manudeli Nov 27, 2026
47a49f8
test(react-query): align compatibility suites with the merged v6 runtime
manudeli Nov 27, 2026
eaec09e
feat(react-query): tree-shake optional observer and cache behavior
manudeli Nov 27, 2026
04cf91a
test(react-query): measure the retained Query runtime and publish bun…
manudeli Nov 27, 2026
ee24924
feat(react-query): acquire the pluggable mutation cache on demand
manudeli Nov 27, 2026
99d796d
feat(react-query): compose query modes and import client operations f…
manudeli Nov 27, 2026
25614bb
feat(query-core): add an independent ESM core with pluggable operations
manudeli Nov 27, 2026
7c40caa
test(react-query): measure package pairs and microfrontend navigation
manudeli Nov 27, 2026
fe52379
feat(react-query): require one of four typed option factories for use…
manudeli Nov 27, 2026
94f0585
test(react-query): verify declaration emit for spread options
manudeli Nov 27, 2026
a01ca71
ci: apply automated fixes
autofix-ci[bot] Nov 27, 2026
5a729ae
fix(react-query): emit public types for skippable suspense options
manudeli Nov 27, 2026
0a1dc6a
Merge remote-tracking branch 'origin/experiment/v6-react-query-plugga…
manudeli Nov 27, 2026
cc141e9
feat(react-query): move single-query behavior and derived flags behin…
manudeli Nov 27, 2026
8f9f62d
docs(react-query): clarify how skipped queries select their render po…
manudeli Nov 27, 2026
15c2885
fix(react-query): preserve v6 imperative query names in the pluggable…
manudeli Nov 27, 2026
9d53c1f
test(react-query): report Query payloads and resolve the pluggable co…
manudeli Nov 27, 2026
3bbafc2
test(react-query): declare the pluggable Vitest test directory
manudeli Nov 27, 2026
26deb35
docs(react-query): prepare post query options before calling the hook
manudeli Nov 27, 2026
0dd3f4e
feat(react-query): opt into error boundaries and isolate page fetching
manudeli Nov 27, 2026
9d6ee6d
feat(query-core-pluggable): import individual cache entry operations …
manudeli Nov 27, 2026
d9201ba
test(react-query): type-check bundle fixtures and their editor imports
manudeli Nov 27, 2026
398e41a
test(query-core-pluggable): type the invalidation fetch mock
manudeli Nov 27, 2026
150b4f0
test(react-query): measure lazy catalog and below-the-fold navigation
manudeli Nov 28, 2026
4eb8551
test(pluggable): isolate compatibility suites from the v6 packages
manudeli Nov 28, 2026
156e2a3
test(pluggable): verify the boolean returned by isFetched
manudeli Nov 28, 2026
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
16 changes: 16 additions & 0 deletions .changeset/react-query-pluggable.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
---
'@tanstack/query-core-pluggable': minor
'@tanstack/react-query-pluggable': minor
---

Add an experimental ESM-only pair for React. `@tanstack/react-query-pluggable` depends on `@tanstack/query-core-pluggable`. Prepare each `useQuery` call with `queryOptions`, `suspenseQueryOptions`, `infiniteQueryOptions`, or `suspenseInfiniteQueryOptions`. Each factory selects the observer and return type. The Suspense factories delegate an initial fetch to the nearest boundary.

Import optional features such as `refetchInterval`, `select`, `placeholderData`, and `serialScope` where the application uses them. Call the v6 imperative readers as `query(client, options)` and `infiniteQuery(client, options)`. Both use fresh cached data and fetch when stale. Other client operations follow the same client-first convention, including `invalidateQueries(client, filters)`. Mutation hooks acquire their cache on demand. Use `getMutationCache(client)` for direct access.

The single-query reader gets its render behavior from the factory. Import result predicates such as `isSuccess(result)`, `isLoading(result)`, and `isFetchingNextPage(result)` wherever a component needs them. They narrow the result for TypeScript. Use `countFetchingQueries(client)` to count fetching queries across a cache. For a variable-length list, use `useQueries` or `useSuspenseQueries`.

Cache-wide lookups and query-state checks are named imports, including `findCachedQuery(cache, filters)`, `findCachedQueries(cache, filters)`, `clearQueryCache(cache)`, and `isQueryActive(query)`.

Four methods on an individual cache entry are now named imports. Use `invalidateCachedQuery(entry)` to mark it invalidated, `resetCachedQuery(entry)` to cancel its fetch and restore its initial state, `getQueryObserverCount(entry)` to count subscribed observers, and `isQueryFetched(entry)` to check for a data or error update. For a filtered operation that also refetches eligible active queries by default, use `invalidateQueries(client, filters)` or `resetQueries(client, filters)`. Inside a component, `isFetched(result)` reads the update history from the hook result.

Ordinary readers handle failures inline by default. Import `throwOnError` and set `throwOnError: [throwOnError, true]` or `throwOnError: [throwOnError, predicate]` to opt into React error boundaries. Suspense readers include boundary handling automatically. Ordinary queries retain default structural sharing. The infinite query fetcher prepares page requests only when the application uses pagination.
104 changes: 104 additions & 0 deletions .github/workflows/react-query-bundle-size.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,104 @@
name: React Query app bundle size

on:
pull_request:
paths:
- '.github/workflows/react-query-bundle-size.yml'
- 'integrations/react/bundle-size/**'
- 'packages/query-core/**'
- 'packages/query-core-pluggable/**'
- 'packages/react-query/**'
- 'packages/react-query-pluggable/**'
- 'scripts/getTsdownConfig.js'
- '.nvmrc'
- 'package.json'
- 'pnpm-lock.yaml'
- 'pnpm-workspace.yaml'

concurrency:
group: ${{ github.workflow }}-${{ github.event.number }}
cancel-in-progress: true

permissions: {}

jobs:
measure:
runs-on: ubuntu-latest
permissions:
contents: read
outputs:
report: ${{ steps.measure.outputs.report }}
analyzer_url: ${{ steps.analyzer.outputs.artifact-url }}
steps:
- uses: actions/checkout@de0fac2e4500dabe0009e67214ff5f5447ce83dd # v6.0.2
with:
ref: ${{ github.event.pull_request.head.sha }}
persist-credentials: false
- uses: TanStack/config/.github/setup@e4b48f16568324f76f467aa4c2aac2f05db632c3
- name: Check out the unmodified PR base
uses: actions/checkout@de0fac2e4500dabe0009e67214ff5f5447ce83dd # v6.0.2
with:
ref: ${{ github.event.pull_request.base.sha }}
path: .bundle-base
persist-credentials: false
- name: Install and build the baseline adapter
working-directory: .bundle-base
run: |
pnpm --filter root --filter '@tanstack/react-query...' install --frozen-lockfile
pnpm --filter '@tanstack/react-query...' run build
- name: Build workspace dependencies
run: pnpm --filter '@tanstack/query-integration-react-bundle-size^...' run build
- name: Type-check the benchmark and both adapters' screens
working-directory: integrations/react/bundle-size
run: pnpm run test:types
- name: Build and measure production apps
id: measure
env:
QUERY_BASE_CHECKOUT: ${{ github.workspace }}/.bundle-base
working-directory: integrations/react/bundle-size
run: |
pnpm run measure
cat dist/report.md >> "$GITHUB_STEP_SUMMARY"
jq -Rsr '"report=" + tojson' dist/report.md >> "$GITHUB_OUTPUT"
- name: Install Chromium
working-directory: integrations/react/bundle-size
run: pnpm run browser:install
- name: Exercise production apps in Chromium
working-directory: integrations/react/bundle-size
run: pnpm run test:browser
- name: Upload interactive bundle treemaps
id: analyzer
uses: actions/upload-artifact@cf430e030ddbb5b0abf93d22962f4752f3646cd9 # v7.0.2
with:
name: react-query-bundle-analyzer
path: integrations/react/bundle-size/dist/analyzer/
if-no-files-found: error
retention-days: 30
comment:
if: github.event.pull_request.head.repo.full_name == github.repository
needs: measure
runs-on: ubuntu-latest
permissions:
pull-requests: write
steps:
- name: Update bundle size comment
env:
GH_TOKEN: ${{ github.token }}
REPO: ${{ github.repository }}
PR_NUMBER: ${{ github.event.number }}
REPORT: ${{ needs.measure.outputs.report }}
ANALYZER_URL: ${{ needs.measure.outputs.analyzer_url }}
run: |
comments="repos/$REPO/issues/$PR_NUMBER/comments"
marker='<!-- react-query-app-bundle-size -->'
id=$(gh api --paginate --slurp "$comments?per_page=100" |
jq -r --arg marker "$marker" '[.[][] | select(.user.login == "github-actions[bot]" and (.body | startswith($marker)))][0].id // empty')
endpoint="$comments"
method=POST
if [[ -n "$id" ]]; then
endpoint="repos/$REPO/issues/comments/$id"
method=PATCH
fi
jq -n --arg marker "$marker" --argjson report "$REPORT" --arg analyzer "$ANALYZER_URL" \
'{body: ($marker + "\n" + $report + "\n[Download the interactive bundle treemaps](" + $analyzer + ")")}' |
gh api --silent --method "$method" "$endpoint" --input -
1 change: 1 addition & 0 deletions integrations/react/bundle-size/.gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
.vitest/
76 changes: 76 additions & 0 deletions integrations/react/bundle-size/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,76 @@
# React Query app bundle size

This workspace builds four browser apps against each adapter’s public package entry point. The read-only app fetches a book list with `useQuery(options)` in v6 and `useQuery(queryOptions(options))` in the pluggable adapter. The paginated app uses the query, infinite-query and mutation option factories to fetch additional pages and save bookmarks in browser storage. The polling app refreshes regular and infinite queries, both with and without Suspense. The pluggable app calls `useQuery` with `queryOptions(options)`, `infiniteQueryOptions(options)`, `suspenseQueryOptions(options)` or `suspenseInfiniteQueryOptions(options)` for each subscriber. The browser test holds the first responses until both dedicated Suspense boundaries show their fallbacks, then checks the resolved data and subsequent refetches. The options app keeps the previous page while fetching, selects the displayed titles, saves bookmarks in a serial scope, and invalidates the bookmark list. Each app uses the default client. The original adapter accepts a numeric interval. The pluggable adapter imports its interval scheduler through the `refetchInterval` option helper.

CI builds the original adapter and its dependencies from the PR's base commit. The stock pair is `@tanstack/react-query` and `@tanstack/query-core`. The experimental pair is `@tanstack/react-query-pluggable` and `@tanstack/query-core-pluggable`. The experimental packages, fixture, bundler and React dependencies come from the PR head. The report records both commit IDs.

## What the PR comment measures

The opening table compares the gzipped Query runtime for each workload. It shows the byte difference and percentage change from v6. The next table lists implementations shipped by v6 that the pluggable build omits for each workload. The comparison checks emitted modules, retained exports and the source map symbols of v6’s built-in polling, selection, placeholder and scope handling. For bulk cache operations it also checks v6's emitted public method names. Expand the Query runtime table for the minified, gzip level 9 and Brotli quality 11 byte counts.

Vite builds the same HTML and React entry points with React, React DOM and their subpaths external. Rolldown groups the retained modules from the adapter and its core package into one ESM chunk. The app and its workload-specific helpers stay in a separate entry chunk. The benchmark measures and compresses the emitted Query chunk directly, including its ESM import and export bindings. Each percentage uses the stock pair’s chunk for the same workload and encoding.

The read-only app displays a failed query through its returned result. Its Query chunk must omit the error reset boundary, render-time error handling and the `shouldThrowError` predicate. The emitted JavaScript must also omit calls to the boundary’s `clearReset` API. The polling app includes the reset boundary for its Suspense queries. A separate consumer builds an ordinary `useQuery` with `throwOnError: [throwOnError, true]`. It must retain the boundary handling and exclude Suspense fetching. All four pluggable workloads must retain `replaceData` and `replaceEqualDeep`, which implement default structural sharing.

The pluggable options app calls `invalidateQueries(client, { queryKey: ['bookmarks'] })`. Every named client operation takes the client first. The benchmark checks retained exports to verify that importing `QueryClient` leaves out `query(client, options)`, `infiniteQuery(client, options)`, `setQueryData` and bulk operations, and that each named operation is available when imported.

For each app, the benchmark verifies that the isolated Query chunk contains the same retained Query module IDs and exports as the deployable browser build and imports only React peer entry points. Both builds reject runtime modules from the other pair or another checkout. Individual probes import operations directly from the public `@tanstack/query-core-pluggable` entry using the React adapter’s dependency scope. Both the read-only and polling apps construct a `QueryClient` and use queries. The pluggable build must retain the query cache and observer and exclude the mutation cache, mutation and mutation observer. Both bookmark apps call `useMutation` and must retain all three mutation modules. The ordinary and infinite option factories select their respective observers. The pluggable adapter exposes `useQuery` for all four modes. Its bundle contains no `useBaseQuery` wrapper, and the bare `useQuery` export leaves out both concrete observers. The benchmark checks the minified Query chunk for the optimistic fetch `Promise.race` in the Suspense workload and its absence in the other three. Each Suspense option factory is also tested independently against its ordinary counterpart. The read-only app excludes the infinite observer, both Suspense factories and their common policy. The polling app exercises all four factories. A separate probe verifies that `suspenseQueryOptions` excludes the infinite factory and observer, and that `suspenseInfiniteQueryOptions` excludes the regular-only factories. Pagination and polling retain the infinite query builder, observer and page fetcher. The read-only and selection apps exclude the page fetcher. Chromium exercises the included implementation by requesting and rendering the second page. All four hook-driven apps exclude both imperative operations. The regular operation is the named `query` export of the client module. Hook-driven apps still retain the core `Query` class. The `infiniteQuery` operation adds page fetching when imported. Additional checks cover polling, infinite queries, selection, placeholder data, serial queues and bulk cache operations. Individual public export probes also check selection, placeholder data and serial queues. The query cache lookups (`findCachedQuery` and `findCachedQueries`), `clearQueryCache`, and active, disabled, static and stale query predicates are measured as named core exports. The invalidation workload retains the filters and refetch predicates it calls, including `invalidateCachedQuery`, `getQueryObserverCount` and `isQueryFetched`. The other three workloads omit these functions. All four omit `resetCachedQuery`; a separate public import probe verifies that it remains available. The benchmark checks all fourteen query result helpers in isolation, then verifies the exact set retained by each screen. The read-only and options apps import `isPending` and `isError`. Pagination additionally imports `isFetching`, and polling reads the query data without any status helpers. The React hydration boundary only restores queries. The universal `hydrate` also restores serial queues from saved mutations.

The PR comment links to the workflow artifact containing an interactive HTML bundle analyzer for each package and workload. Open `dist/analyzer/<workload>/<adapter>.html` locally after running the benchmark. Select the `query-runtime` chunk to explore its constituent sources. The treemap shows module contributions from source maps. The tables use actual compressed chunk bytes.

## Lazy route navigation

Open the catalog, visit Bookmarks, load a second page, then return to the catalog. One React root and one `QueryClientProvider` stay mounted for the whole visit. The shell imports the catalog at startup. `React.lazy` loads the bookmarks screen on its first render, and a React `Suspense` boundary shows a fallback while that JavaScript arrives. The catalog uses an ordinary data query.

For the above-the-fold (ATF) and below-the-fold (BTF) layout, open the same app with `?layout=scroll`. The catalog renders immediately. An `IntersectionObserver` mounts the bookmarks component the first time its shelf intersects the viewport. Merely placing a mounted `React.lazy` component below the fold would request its module on the initial render. The navigation and scroll examples share the same dynamic import and emitted files. [React shell and viewport trigger](./src/lazy/main.tsx)

The catalog imports its ordinary-query helper from a dedicated module. Keeping pagination and mutation imports on the bookmarks side gives the bundler a route boundary to follow. In stock v6 the shared client constructs a mutation cache, and its core fetch path references infinite-page behavior. The pluggable pair can defer both implementations until the bookmarks component loads. [v6 client](../../../packages/query-core/src/queryClient.ts) · [v6 fetch path](../../../packages/query-core/src/query.ts) · [Catalog hook](./src/pluggable-catalog.ts) · [Paginated hook](./src/pluggable-query.ts)

The lazy-route table reports Query bytes for the cold catalog, the first trip to Bookmarks, both screens together, and the return trip. Each URL is counted once in the cumulative total. A larger incremental download on the second route can go along with a smaller first load when more of the feature's code can wait for the click. Read the phase rows alongside the total. [Measurement](./lazyRoutes.ts) · [Chromium navigation test](./browser/lazyRoutes.test.ts)

| To explore | Example code |
| --------------------------------------------------------------------------- | ----------------------------------------------------------------------------------------------------------------- |
| Reading a list and handling pending and error states | [Catalog](./src/query.tsx) |
| Fetching another page and saving a bookmark | [Paginated list and mutation](./src/paginated.tsx) |
| Selecting titles, showing placeholders and invalidating after queued writes | [Screen](./src/options.tsx) · [v6 options](./src/v6-options.ts) · [Pluggable options](./src/pluggable-options.ts) |
| Polling regular, infinite and Suspense queries | [Polling screen](./src/polling.tsx) · [Pluggable interval](./src/pluggable-interval.ts) |

## Microfrontend navigation

A shell loads the catalog first and the paginated bookmarks screen on navigation. Both remotes use the host’s React and React DOM and create a client when mounted. In the independent deployment, each remote is built on its own and has a separate Query URL. In the shared deployment, the shell serves one ESM Query chunk containing both routes’ imports. The table reports the gzip bytes of the Query URLs needed for the catalog alone and for the complete journey. Chromium verifies the requests on both visits and on returning to the catalog. The measured bytes describe JavaScript transfer. They do not measure cross-client data caching.

## Run locally

After installing workspace dependencies, build the packages, type-check the fixture, and measure both adapters from the repository root.

```sh
pnpm --filter '@tanstack/query-integration-react-bundle-size^...' run build
pnpm --filter @tanstack/query-integration-react-bundle-size run test:types
pnpm --filter @tanstack/query-integration-react-bundle-size run measure
```

`test:types` checks the measurement tools, microfrontend host and browser tests. It checks the workload apps and remotes against both adapters' public types. The command also opens the app, remote and adapter hooks in the TypeScript language server to check that the editor resolves the same imports.

To reproduce the CI comparison, use a clean worktree of the base commit. Replace `BASE_SHA` with the base commit from the report.

```sh
git worktree add --detach ../query-bundle-base BASE_SHA
pnpm --dir ../query-bundle-base --filter root --filter '@tanstack/react-query...' install --frozen-lockfile
pnpm --dir ../query-bundle-base --filter '@tanstack/react-query...' run build
QUERY_BASE_CHECKOUT="$PWD/../query-bundle-base" pnpm --filter @tanstack/query-integration-react-bundle-size run measure
```

Read the summary and detailed tables in `integrations/react/bundle-size/dist/report.md`. Serve a directory under `dist/<workload>/<adapter>` to try the built app.

To try the lazy routes, run `pnpm exec vite preview --outDir dist` from this directory after measuring. Open `/lazy-routes/react-query/` or `/lazy-routes/react-query-pluggable/` on the printed URL. Append `?layout=scroll` to try scrolling to the shelf. The Network panel shows which JavaScript each visit requests.

Run the production apps, lazy routes and microfrontend journeys in Chromium after measuring.

```sh
cd integrations/react/bundle-size
pnpm exec playwright install chromium
pnpm test:browser
pnpm test:browser:ui
```

The last command starts Vitest in watch mode with a browser UI for inspecting and rerunning each adapter’s scenarios.
Loading
Loading