Skip to content

docs(example): batching#11008

Open
TkDodo wants to merge 6 commits into
mainfrom
feature/dataloader-example
Open

docs(example): batching#11008
TkDodo wants to merge 6 commits into
mainfrom
feature/dataloader-example

Conversation

@TkDodo

@TkDodo TkDodo commented Jun 30, 2026

Copy link
Copy Markdown
Collaborator

Summary by CodeRabbit

  • New Features
    • Added a new React “batching” example that loads multiple characters efficiently using shared request batching.
    • Updated the example UI to fetch multiple characters via React Query and render loading, error, and “not found” states.
  • Documentation
    • Added a README with setup and run instructions for the batching example.
  • Chores
    • Added example scaffolding: Vite/TypeScript/ESLint configuration, HTML entrypoint, and a .gitignore for common local/build/test artifacts.

@nx-cloud

nx-cloud Bot commented Jun 30, 2026

Copy link
Copy Markdown

View your CI Pipeline Execution ↗ for commit cef22bb

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

☁️ Nx Cloud last updated this comment at 2026-06-30 19:26:06 UTC

@coderabbitai

coderabbitai Bot commented Jun 30, 2026

Copy link
Copy Markdown
Contributor

Review Change Stack

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

Adds a new examples/react/batching React example with Vite, TypeScript, and ESLint setup, plus a batched character loader and a React Query UI that loads and renders Rick and Morty characters by id.

Changes

React Batching Example

Layer / File(s) Summary
Project scaffold and tooling
examples/react/batching/package.json, tsconfig.json, vite.config.ts, eslint.config.js, index.html, .gitignore, README.md
Adds the example package metadata, build/lint scripts, TypeScript and Vite config, HTML entrypoint, ignore rules, and run instructions.
Character batching loader
examples/react/batching/src/character-loader.ts
Adds CharacterT, deferred request handling, batched API fetching, and the exported character-loading function.
React Query app
examples/react/batching/src/index.tsx
Sets up a shared QueryClient, query options, batched character rendering, validated comma-separated id input, and the root render bootstrap with ReactQueryDevtools.

Estimated code review effort

🎯 3 (Moderate) | ⏱️ ~20 minutes

Poem

🐇 I thump through the bytes with a happy bop,
Batch the chars together and never stop.
Query by query, the garden grows bright,
With devtools and root mount all snug and right.

🚥 Pre-merge checks | ✅ 3 | ❌ 2

❌ Failed checks (2 warnings)

Check name Status Explanation Resolution
Description check ⚠️ Warning No PR description was provided, so the required Changes, Checklist, and Release Impact sections are missing. Add the template sections with a brief summary of changes, checklist items, testing performed, and release impact.
Docstring Coverage ⚠️ Warning Docstring coverage is 0.00% which is insufficient. The required threshold is 80.00%. Write docstrings for the functions missing them to satisfy the coverage threshold.
✅ Passed checks (3 passed)
Check name Status Explanation
Title check ✅ Passed The title is concise and refers to the batching example, but it understates the main code-heavy change.
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.
✨ Finishing Touches
🧪 Generate unit tests (beta)
  • Create PR with unit tests
  • Commit unit tests in branch feature/dataloader-example

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

@github-actions

Copy link
Copy Markdown
Contributor

🚀 Changeset Version Preview

No changeset entries found. Merging this PR will not cause a version bump for any packages.

@socket-security

socket-security Bot commented Jun 30, 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@​tanstack/​react-pacer@​0.22.110010010091100

View full report

@pkg-pr-new

pkg-pr-new Bot commented Jun 30, 2026

Copy link
Copy Markdown
More templates

@tanstack/angular-query-experimental

npm i https://pkg.pr.new/@tanstack/angular-query-experimental@11008

@tanstack/eslint-plugin-query

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

@tanstack/lit-query

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

@tanstack/preact-query

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

@tanstack/preact-query-devtools

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

@tanstack/preact-query-persist-client

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

@tanstack/query-async-storage-persister

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

@tanstack/query-broadcast-client-experimental

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

@tanstack/query-core

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

@tanstack/query-devtools

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

@tanstack/query-persist-client-core

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

@tanstack/query-sync-storage-persister

npm i https://pkg.pr.new/@tanstack/query-sync-storage-persister@11008

@tanstack/react-query

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

@tanstack/react-query-devtools

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

@tanstack/react-query-next-experimental

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

@tanstack/react-query-persist-client

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

@tanstack/solid-query

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

@tanstack/solid-query-devtools

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

@tanstack/solid-query-persist-client

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

@tanstack/svelte-query

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

@tanstack/svelte-query-devtools

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

@tanstack/svelte-query-persist-client

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

@tanstack/vue-query

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

@tanstack/vue-query-devtools

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

commit: cef22bb

@github-actions

Copy link
Copy Markdown
Contributor

size-limit report 📦

Path Size
react full 12.13 KB (0%)
react minimal 9.08 KB (0%)

@coderabbitai coderabbitai Bot left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Actionable comments posted: 4

🧹 Nitpick comments (1)
examples/react/batching/package.json (1)

15-21: 📐 Maintainability & Code Quality | 🔵 Trivial | ⚡ Quick win

Align the React type packages with React 19.

@types/react and @types/react-dom are still on 18.x while the runtime is React 19, so this example type-checks against an older API surface. Update both to 19.x to keep the scaffold consistent.

🤖 Prompt for AI Agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.

In `@examples/react/batching/package.json` around lines 15 - 21, The example’s
React type packages are mismatched with the runtime, so update the
devDependencies in package.json to use the React 19 type packages for both
`@types/react` and `@types/react-dom`. Keep the versions aligned with the existing
React and ReactDOM 19 entries so the batching example type-checks against the
same API surface as the runtime.
🤖 Prompt for all review comments with AI agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.

Inline comments:
In `@examples/react/batching/.gitignore`:
- Around line 11-13: The batching example is ignoring the wrong Vite build
output directory, so generated artifacts can still be committed. Update the
ignore entry in this example’s .gitignore to match the actual default output
from the Vite setup used by batching, and verify it aligns with vite.config.ts
and the example’s build output path rather than /build.

In `@examples/react/batching/index.html`:
- Line 9: The document title for the batching demo is still using the generic
Basic Example App text, which makes the browser tab misleading. Update the title
in the HTML document’s title element so it matches the batching example naming
used by this demo, keeping the change localized to the example’s main HTML entry
point.

In `@examples/react/batching/src/index.tsx`:
- Around line 54-55: The character card is displaying the React Query state
instead of the API-provided character status. In the component that renders the
status text, update the `character.status` reference to use
`character.data.status` so the UI shows the actual character status; keep the
change localized to the status rendering in the React batching example.
- Around line 92-107: The validation flow in the React batching example leaves
stale `ids` in state when parsing fails, so the `onClick` handler for the “Load
characters” button can still use the last valid value even while `error` is
shown. Update the input validation logic around the `setIds`, `setIdsToLoad`,
and `setError` state updates so invalid input either clears the pending IDs or
prevents loading until the value is valid, ensuring the button action cannot
submit stale IDs after a failed parse.

---

Nitpick comments:
In `@examples/react/batching/package.json`:
- Around line 15-21: The example’s React type packages are mismatched with the
runtime, so update the devDependencies in package.json to use the React 19 type
packages for both `@types/react` and `@types/react-dom`. Keep the versions aligned
with the existing React and ReactDOM 19 entries so the batching example
type-checks against the same API surface as the runtime.
🪄 Autofix (Beta)

Fix all unresolved CodeRabbit comments on this PR:

  • Push a commit to this branch (recommended)
  • Create a new PR with the fixes

ℹ️ Review info
⚙️ Run configuration

Configuration used: defaults

Review profile: CHILL

Plan: Pro

Run ID: 675ebabf-0796-4c6e-8b6e-71e2860164fd

📥 Commits

Reviewing files that changed from the base of the PR and between d6798b5 and 87b017c.

⛔ Files ignored due to path filters (2)
  • examples/react/batching/public/emblem-light.svg is excluded by !**/*.svg
  • pnpm-lock.yaml is excluded by !**/pnpm-lock.yaml
📒 Files selected for processing (9)
  • examples/react/batching/.gitignore
  • examples/react/batching/README.md
  • examples/react/batching/eslint.config.js
  • examples/react/batching/index.html
  • examples/react/batching/package.json
  • examples/react/batching/src/character-loader.ts
  • examples/react/batching/src/index.tsx
  • examples/react/batching/tsconfig.json
  • examples/react/batching/vite.config.ts

Comment on lines +11 to +13
# production
/build

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

📐 Maintainability & Code Quality | 🟡 Minor | ⚡ Quick win

Ignore Vite’s actual build output directory.

Lines 11-13 ignore /build, but examples/react/batching/vite.config.ts does not override Vite’s default outDir, so this example will emit dist/ instead. As written, generated artifacts can be committed accidentally.

Suggested fix
 # production
-/build
+/dist
📝 Committable suggestion

‼️ IMPORTANT
Carefully review the code before committing. Ensure that it accurately replaces the highlighted code, contains no missing lines, and has no issues with indentation. Thoroughly test & benchmark the code to ensure it meets the requirements.

Suggested change
# production
/build
# production
/dist
🤖 Prompt for AI Agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.

In `@examples/react/batching/.gitignore` around lines 11 - 13, The batching
example is ignoring the wrong Vite build output directory, so generated
artifacts can still be committed. Update the ignore entry in this example’s
.gitignore to match the actual default output from the Vite setup used by
batching, and verify it aligns with vite.config.ts and the example’s build
output path rather than /build.

<meta name="viewport" content="width=device-width, initial-scale=1" />
<meta name="theme-color" content="#000000" />

<title>TanStack Query React Basic Example App</title>

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

📐 Maintainability & Code Quality | 🟡 Minor | ⚡ Quick win

Update the document title to match the batching example.

Line 9 still says “Basic Example App”, which looks copied from another example and makes the browser tab misleading for this demo.

Suggested fix
-    <title>TanStack Query React Basic Example App</title>
+    <title>TanStack Query React Batching Example App</title>
📝 Committable suggestion

‼️ IMPORTANT
Carefully review the code before committing. Ensure that it accurately replaces the highlighted code, contains no missing lines, and has no issues with indentation. Thoroughly test & benchmark the code to ensure it meets the requirements.

Suggested change
<title>TanStack Query React Basic Example App</title>
<title>TanStack Query React Batching Example App</title>
🤖 Prompt for AI Agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.

In `@examples/react/batching/index.html` at line 9, The document title for the
batching demo is still using the generic Basic Example App text, which makes the
browser tab misleading. Update the title in the HTML document’s title element so
it matches the batching example naming used by this demo, keeping the change
localized to the example’s main HTML entry point.

Comment on lines +54 to +55
<p style={{ marginTop: 0, marginBottom: 2 }}>
Status: {character.status}

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🎯 Functional Correctness | 🟡 Minor | ⚡ Quick win

Render the character's status, not the query status.

character.status here is the React Query state (pending / error / success), so every loaded card will show success instead of the API's character status. Use character.data.status for this field.

Suggested fix
           <p style={{ marginTop: 0, marginBottom: 2 }}>
-            Status: {character.status}
+            Status: {character.data.status}
           </p>
📝 Committable suggestion

‼️ IMPORTANT
Carefully review the code before committing. Ensure that it accurately replaces the highlighted code, contains no missing lines, and has no issues with indentation. Thoroughly test & benchmark the code to ensure it meets the requirements.

Suggested change
<p style={{ marginTop: 0, marginBottom: 2 }}>
Status: {character.status}
<p style={{ marginTop: 0, marginBottom: 2 }}>
Status: {character.data.status}
🤖 Prompt for AI Agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.

In `@examples/react/batching/src/index.tsx` around lines 54 - 55, The character
card is displaying the React Query state instead of the API-provided character
status. In the component that renders the status text, update the
`character.status` reference to use `character.data.status` so the UI shows the
actual character status; keep the change localized to the status rendering in
the React batching example.

Comment on lines +92 to +107
if (allValid) {
setIds(ids)
setError('')
} else {
setError('Invalid.. only use numbers and comma')
}
}}
/>
</div>

{error ? <h3 style={{ color: 'red' }}>{error}</h3> : null}

<button
type="button"
onClick={() => {
setIdsToLoad(ids)

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🎯 Functional Correctness | 🟠 Major | ⚡ Quick win

Clear or block stale IDs after validation fails.

When parsing fails, ids keeps the last valid value. Clicking Load characters after an invalid edit will therefore fetch stale IDs even though the UI is showing an error.

Suggested fix
             if (allValid) {
               setIds(ids)
               setError('')
             } else {
+              setIds([])
               setError('Invalid.. only use numbers and comma')
             }
@@
       <button
         type="button"
+        disabled={!!error || ids.length === 0}
         onClick={() => {
           setIdsToLoad(ids)
         }}
       >
📝 Committable suggestion

‼️ IMPORTANT
Carefully review the code before committing. Ensure that it accurately replaces the highlighted code, contains no missing lines, and has no issues with indentation. Thoroughly test & benchmark the code to ensure it meets the requirements.

Suggested change
if (allValid) {
setIds(ids)
setError('')
} else {
setError('Invalid.. only use numbers and comma')
}
}}
/>
</div>
{error ? <h3 style={{ color: 'red' }}>{error}</h3> : null}
<button
type="button"
onClick={() => {
setIdsToLoad(ids)
if (allValid) {
setIds(ids)
setError('')
} else {
setIds([])
setError('Invalid.. only use numbers and comma')
}
}}
/>
</div>
{error ? <h3 style={{ color: 'red' }}>{error}</h3> : null}
<button
type="button"
disabled={!!error || ids.length === 0}
onClick={() => {
setIdsToLoad(ids)
🤖 Prompt for AI Agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.

In `@examples/react/batching/src/index.tsx` around lines 92 - 107, The validation
flow in the React batching example leaves stale `ids` in state when parsing
fails, so the `onClick` handler for the “Load characters” button can still use
the last valid value even while `error` is shown. Update the input validation
logic around the `setIds`, `setIdsToLoad`, and `setError` state updates so
invalid input either clears the pending IDs or prevents loading until the value
is valid, ensuring the button action cannot submit stale IDs after a failed
parse.

@TkDodo TkDodo changed the title docs(example): dataloader docs(example): batching Jun 30, 2026
Comment thread examples/react/batching/src/character-loader.ts Outdated
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.

2 participants