examples: Add a new TanStack Start example for typed readable streams #5363
main fromrefs/pull/5363/head·merged by schiller-manuel(GitHub profile, opens in a new tab) Turns out typed Readable Streams are in high demand thanks to AI apps (I actually use them myself with TanStack Start), but we didn't have any examples for it yet, so I added one.
I'm happy to update the docs too, but not sure where.
Summary by CodeRabbit#
New Features
- Added a runnable React example demonstrating two typed streaming approaches from server functions, with UI controls to trigger streams and view accumulated results; includes project config for React 19 and Vite.
Documentation
- Added a dedicated guide on streaming typed data from server functions (typed ReadableStreams and async generators).
- Reorganized server-functions docs by splitting “Streaming” and “Raw Responses” and linking to the new guide.
Chores
- Added example project tooling and TypeScript config for the demo.
- 1
Walkthrough#
Adds a new React example and docs demonstrating typed streaming from server functions (Typed ReadableStream and async generators), new example project scaffolding (router, generated route tree, Vite/TS configs, styles), and reorganizes server-functions docs to separate Streaming and Raw Responses sections.
Changes#
Cohort / File(s) Summary Docs — Streaming guide docs/router/framework/react/guide/streaming-data-from-server-functions.mdNew guide showing two typed streaming approaches (Typed ReadableStreamand async generators) with TypeScript server and client examples and references to an example repo.Docs — Server functions reorg docs/start/framework/react/server-functions.mdRenamed "Streaming & Raw Responses" → "Streaming"; replaced streaming content with link to new guide and added a separate "Raw Responses" subsection. Example — Project config examples/react/start-streaming-data-from-server-functions/package.json,examples/react/start-streaming-data-from-server-functions/tsconfig.json,examples/react/start-streaming-data-from-server-functions/vite.config.tsNew example package manifest, strict TS config with path alias, and Vite config (dev port 3000, plugins: tsconfig-paths, tanstack-start, react). Example — Router & types examples/react/start-streaming-data-from-server-functions/src/routeTree.gen.ts,examples/react/start-streaming-data-from-server-functions/src/router.tsxAdds generated typed route tree and getRouter()creating a TanStack router; includes TypeScript module augmentations for@tanstack/react-routerand@tanstack/react-start.Example — App shell & styles examples/react/start-streaming-data-from-server-functions/src/routes/__root.tsx,examples/react/start-streaming-data-from-server-functions/src/styles/app.cssNew root route/document component wiring head, global CSS import, devtools, script injection, and layout/styles for the demo. Example — Streaming route examples/react/start-streaming-data-from-server-functions/src/routes/index.tsxImplements demo route with Zod TextParttype, aReadableStream<TextPart>server function, an async-generator server function, client consumption for both, UI buttons, and stream output display.Sequence Diagram(s)#
sequenceDiagram autonumber actor U as User participant C as React Client (Route) participant SF as Server Function participant Stream as Stream / Generator U->>C: Click "Stream (ReadableStream)" or "Stream (Async Gen)" alt ReadableStream flow C->>SF: call streamingResponseFn() SF-->>C: returns ReadableStream<TextPart> loop chunks C->>Stream: reader.read() Stream-->>C: chunk (TextPart) C->>C: append chunk to UI end else Async generator flow C->>SF: call streamingWithAnAsyncGeneratorFn() SF-->>C: returns AsyncGenerator<TextPart> loop for await SF-->>C: yield (TextPart) C->>C: append chunk to UI end end C-->>U: render accumulated streamed textEstimated code review effort#
🎯 3 (Moderate) | ⏱️ ~25 minutes
Possibly related PRs#
- TanStack/router#5211 — Related example/docs changes and adoption of
createFileRoute/ router setup patterns used in this example.
Suggested reviewers#
- schiller-manuel
- birkskyum
Poem#
A nibble of bytes, a hop and a beam, I stream little carrots down a typed little stream. Chunks validated, one hop at a time, I stitch them in order, rhythmic and prime. Hooray for servers that speak in kind—🥕🐇
Pre-merge checks and finishing touches#
❌ 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%. You can run @coderabbitai generate docstringsto improve docstring coverage.✅ Passed checks (2 passed)
Check name Status Explanation Description Check ✅ Passed Check skipped - CodeRabbit’s high-level summary is enabled. Title Check ✅ Passed The title accurately and concisely summarizes the main change by indicating that a new TanStack Start example for typed readable streams is being added under the examples directory, making it immediately clear to reviewers what this pull request introduces. ✨ Finishing touches
- 📝 Generate docstrings
🧪 Generate unit tests (beta)
- Create PR with unit tests
- Post copyable unit tests in a comment
📜 Recent review details
Configuration used: CodeRabbit UI
Review profile: CHILL
Plan: Pro
📥 Commits
Reviewing files that changed from the base of the PR and between b5fd9bad7b6cfc77c708519d9c27620177864901 and e884da1ed629a257ace99a92b5354cdc734ca636.
📒 Files selected for processing (2)
docs/router/framework/react/guide/streaming-data-from-server-functions.md(1 hunks)examples/react/start-streaming-data-from-server-functions/src/routes/index.tsx(1 hunks)
🚧 Files skipped from review as they are similar to previous changes (2)
- examples/react/start-streaming-data-from-server-functions/src/routes/index.tsx
- docs/router/framework/react/guide/streaming-data-from-server-functions.md
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.
Comment `@coderabbitai help` to get the list of available commands and usage tips.- TanStack/router#5211 — Related example/docs changes and adoption of
Actionable comments posted: 2
📜 Review details
Configuration used: CodeRabbit UI
Review profile: CHILL
Plan: Pro
📥 Commits
Reviewing files that changed from the base of the PR and between 0d3bba8978e9bd280a02662ce0da45bf7ccef4b3 and 31c2a5daa513cc3feea2370951c9b3694e67f943.
⛔ Files ignored due to path filters (1)
examples/react/start-typed-readable-stream/public/favicon.icois excluded by!**/*.ico
📒 Files selected for processing (8)
examples/react/start-typed-readable-stream/package.json(1 hunks)examples/react/start-typed-readable-stream/src/routeTree.gen.ts(1 hunks)examples/react/start-typed-readable-stream/src/router.tsx(1 hunks)examples/react/start-typed-readable-stream/src/routes/__root.tsx(1 hunks)examples/react/start-typed-readable-stream/src/routes/index.tsx(1 hunks)examples/react/start-typed-readable-stream/src/styles/app.css(1 hunks)examples/react/start-typed-readable-stream/tsconfig.json(1 hunks)examples/react/start-typed-readable-stream/vite.config.ts(1 hunks)
🧰 Additional context used
📓 Path-based instructions (4)
examples/{react,solid}/**
📄 CodeRabbit inference engine (AGENTS.md)
Keep example applications under examples/react/ and examples/solid/
Files:
examples/react/start-typed-readable-stream/tsconfig.jsonexamples/react/start-typed-readable-stream/src/routes/__root.tsxexamples/react/start-typed-readable-stream/vite.config.tsexamples/react/start-typed-readable-stream/src/routes/index.tsxexamples/react/start-typed-readable-stream/src/routeTree.gen.tsexamples/react/start-typed-readable-stream/package.jsonexamples/react/start-typed-readable-stream/src/styles/app.cssexamples/react/start-typed-readable-stream/src/router.tsx
**/*.{ts,tsx}
📄 CodeRabbit inference engine (AGENTS.md)
Use TypeScript in strict mode with extensive type safety across the codebase
Files:
examples/react/start-typed-readable-stream/src/routes/__root.tsxexamples/react/start-typed-readable-stream/vite.config.tsexamples/react/start-typed-readable-stream/src/routes/index.tsxexamples/react/start-typed-readable-stream/src/routeTree.gen.tsexamples/react/start-typed-readable-stream/src/router.tsx
**/src/routes/**
📄 CodeRabbit inference engine (AGENTS.md)
Place file-based routes under src/routes/ directories
Files:
examples/react/start-typed-readable-stream/src/routes/__root.tsxexamples/react/start-typed-readable-stream/src/routes/index.tsx
**/package.json
📄 CodeRabbit inference engine (AGENTS.md)
Use workspace:* protocol for internal dependencies in package.json files
Files:
examples/react/start-typed-readable-stream/package.json
🧠 Learnings (2)
📚 Learning: 2025-09-23T17:36:12.598Z
Learnt from: CR PR: TanStack/router#0 File: AGENTS.md:0-0 Timestamp: 2025-09-23T17:36:12.598Z Learning: Applies to **/*.{ts,tsx} : Use TypeScript in strict mode with extensive type safety across the codebaseApplied to files:
examples/react/start-typed-readable-stream/tsconfig.json
📚 Learning: 2025-10-01T18:31:35.420Z
Learnt from: schiller-manuel PR: TanStack/router#5330 File: e2e/react-start/custom-basepath/src/routeTree.gen.ts:58-61 Timestamp: 2025-10-01T18:31:35.420Z Learning: Do not review files named `routeTree.gen.ts` in TanStack Router repositories, as these are autogenerated files that should not be manually modified.Applied to files:
examples/react/start-typed-readable-stream/src/routeTree.gen.ts
🧬 Code graph analysis (3)
examples/react/start-typed-readable-stream/src/routes/__root.tsx (2)
examples/react/start-typed-readable-stream/src/routes/index.tsx (1)
Route(60-62)
packages/react-router-devtools/src/TanStackRouterDevtools.tsx (1)
TanStackRouterDevtools(46-126)
examples/react/start-typed-readable-stream/src/routes/index.tsx (1)
examples/react/start-typed-readable-stream/src/routes/__root.tsx (1)
Route(13-18)
examples/react/start-typed-readable-stream/src/routeTree.gen.ts (2)
e2e/react-router/js-only-file-based/src/routeTree.gen.js (2)
IndexRoute(30-34)rootRouteChildren(90-94)
examples/react/start-typed-readable-stream/src/router.tsx (1)
getRouter(4-14)
🔇 Additional comments (2)
examples/react/start-typed-readable-stream/tsconfig.json (1)
1-22: LGTM!The TypeScript configuration correctly enables strict mode with extensive type safety, aligning with the project's coding standards. The modern settings (ESNext, Bundler resolution, ES2022 target) are appropriate for this Vite-based React example.
Based on learnings.
examples/react/start-typed-readable-stream/src/routes/index.tsx (1)
64-100: LGTM!The client-side streaming implementation correctly demonstrates typed ReadableStream usage. The code properly handles the stream reader, maintains type safety (lines 81-83), and updates the UI incrementally as chunks arrive.
examples/react/start-typed-readable-stream/src/routes/__root.tsx lines 36 to 37OutdatedResolvedby coderabbitai[bot](GitHub profile, opens in a new tab)@@ -0,0 +17,21 @@17+ component: RootComponent,18+})19+20+function RootComponent() {21+ return (22+ <RootDocument>23+ <Outlet />24+ </RootDocument>25+ )26+}27+28+function RootDocument({ children }: { children: React.ReactNode }) {29+ return (30+ <html>31+ <head>32+ <HeadContent />33+ </head>34+ <body>35+ <div>36+ <Link to="/">Index</Link>37+ <Link to="/about">About</Link>⚠️ Potential issue | 🟡 Minor
Broken navigation link to non-existent route.
The navigation includes a link to "/about", but no about route is defined in this example. This will result in a 404 error when users click the link.
Consider either:
- Removing the about link
- Adding a placeholder about route
Apply this diff to remove the broken link:
<div> <Link to="/">Index</Link> - <Link to="/about">About</Link> </div>🤖 Prompt for AI Agents
In examples/react/start-typed-readable-stream/src/routes/__root.tsx around lines 36 to 37, the navigation contains a Link to "/about" that points to a non-existent route; remove the <Link to="/about">About</Link> entry from the nav (or alternatively add a corresponding about route file if you prefer to keep the link) so clicks no longer lead to a 404.✅ Addressed in commits 0d3bba8 to 5d18df4
@@ -0,0 +34,21 @@34+ choices: [35+ {36+ delta: { content: `Number #${i + 1}: ${n}\n` },37+ index: i,38+ finish_reason: null,39+ },40+ ],41+ }),42+ )43+44+ // This `ReadableStream` is typed, so each chunk45+ // will be of type `TextPart`.46+ const stream = new ReadableStream<TextPart>({47+ async start(controller) {48+ for (const message of messages) {49+ await sleep(500)50+ controller.enqueue(message)51+ }52+ sleep(500)53+ controller.close()54+ },⚠️ Potential issue | 🔴 Critical
Critical: Missing
awaitbefore final sleep call.Line 52 calls
sleep(500)withoutawait, causing the stream to close immediately instead of waiting 500ms after the last message. This can result in the last chunk being dropped or incomplete.Apply this diff to fix the missing await:
for (const message of messages) { await sleep(500) controller.enqueue(message) } - sleep(500) + await sleep(500) controller.close()📝 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 change46- const stream = new ReadableStream<TextPart>({47- async start(controller) {48- for (const message of messages) {49- await sleep(500)50- controller.enqueue(message)51- }52- sleep(500)53- controller.close()54- },46+ const stream = new ReadableStream<TextPart>({47+ async start(controller) {48+ for (const message of messages) {49+ await sleep(500)50+ controller.enqueue(message)51+ }52+ await sleep(500)53+ controller.close()54+ },🤖 Prompt for AI Agents
In examples/react/start-typed-readable-stream/src/routes/index.tsx around lines 46 to 54, the final sleep(500) call is not awaited so controller.close() runs immediately; change the code to await the final sleep before calling controller.close() so the stream waits 500ms after the last message is enqueued and the last chunk is not dropped.More templates
- tanstack-router-solid-example-basic
- tanstack-router-solid-example-basic-devtools-panel
- tanstack-router-solid-example-basic-file-based
- tanstack-router-solid-example-basic-non-nested-devtools
- tanstack-router-solid-example-basic-solid-query
- tanstack-router-solid-example-basic-solid-query-file-based
- tanstack-router-solid-example-basic-ssr-streaming-file-based
- tanstack-router-solid-example-kitchen-sink-file-based
- tanstack-router-solid-example-quickstart-file-based
- tanstack-solid-start-example-bare
- tanstack-solid-start-example-basic
- tanstack-solid-start-example-basic-static
- tanstack-router-react-example-authenticated-routes
- tanstack-router-react-example-authenticated-routes-firebase
- tanstack-router-react-example-basic
- tanstack-router-react-example-basic-default-search-params
- tanstack-router-react-example-basic-devtools-panel
- tanstack-router-react-example-basic-file-based
- tanstack-router-react-example-basic-non-nested-devtools
- tanstack-router-react-example-react-query
- tanstack-router-react-example-basic-react-query-file-based
- tanstack-router-react-example-basic-ssr-file-based
- tanstack-router-react-example-basic-ssr-streaming-file-based
- tanstack-router-react-example-basic-virtual-file-based
- tanstack-router-react-example-basic-virtual-inside-file-based
- tanstack-router-react-example-deferred-data
- tanstack-router-i18n-paraglide
- tanstack-router-react-example-kitchen-sink
- tanstack-router-react-example-kitchen-sink-file-based
- tanstack-router-react-example-kitchen-sink-react-query
- tanstack-router-react-example-kitchen-sink-react-query-file-based
- tanstack-router-react-example-large-file-based
- tanstack-router-react-example-location-masking
- tanstack-router-react-example-navigation-blocking
- tanstack-router-react-example-quickstart
- tanstack-router-react-example-quickstart-esbuild-file-based
- tanstack-router-react-example-quickstart-file-based
- tanstack-router-react-example-quickstart-rspack-file-based
- tanstack-router-react-example-quickstart-webpack-file-based
- router-monorepo-react-query
- router-mono-simple
- router-mono-simple-lazy
- tanstack-router-react-example-scroll-restoration
- tanstack-search-validator-adapters
- tanstack-start-example-bare
- tanstack-start-example-basic
- tanstack-start-example-basic-auth
- tanstack-start-example-basic-cloudflare
- tanstack-start-example-basic-react-query
- tanstack-start-example-basic-static
- tanstack-start-bun-hosting
- tanstack-start-example-convex-trellaux
- tanstack-start-example-counter
- tanstack-start-i18n-paraglide
- tanstack-start-example-large
- tanstack-start-example-material-ui
- tanstack-start-streaming-data-from-server-functions
- tanstack-start-example-supabase-basic
- tanstack-start-tailwind-v4
- tanstack-start-example-trellaux
- tanstack-start-example-workos
- tanstack-router-react-example-view-transitions
- tanstack-router-react-example-with-framer-motion
- tanstack-router-react-example-with-trpc
- tanstack-router-react-example-with-trpc-react-query
@tanstack/arktype-adapter
npm i https://pkg.pr.new/TanStack/router/@tanstack/arktype-adapter@5363@tanstack/directive-functions-plugin
npm i https://pkg.pr.new/TanStack/router/@tanstack/directive-functions-plugin@5363@tanstack/eslint-plugin-router
npm i https://pkg.pr.new/TanStack/router/@tanstack/eslint-plugin-router@5363@tanstack/history
npm i https://pkg.pr.new/TanStack/router/@tanstack/history@5363@tanstack/nitro-v2-vite-plugin
npm i https://pkg.pr.new/TanStack/router/@tanstack/nitro-v2-vite-plugin@5363@tanstack/react-router
npm i https://pkg.pr.new/TanStack/router/@tanstack/react-router@5363@tanstack/react-router-devtools
npm i https://pkg.pr.new/TanStack/router/@tanstack/react-router-devtools@5363@tanstack/react-router-ssr-query
npm i https://pkg.pr.new/TanStack/router/@tanstack/react-router-ssr-query@5363@tanstack/react-start
npm i https://pkg.pr.new/TanStack/router/@tanstack/react-start@5363@tanstack/react-start-client
npm i https://pkg.pr.new/TanStack/router/@tanstack/react-start-client@5363@tanstack/react-start-server
npm i https://pkg.pr.new/TanStack/router/@tanstack/react-start-server@5363@tanstack/router-cli
npm i https://pkg.pr.new/TanStack/router/@tanstack/router-cli@5363@tanstack/router-core
npm i https://pkg.pr.new/TanStack/router/@tanstack/router-core@5363@tanstack/router-devtools
npm i https://pkg.pr.new/TanStack/router/@tanstack/router-devtools@5363@tanstack/router-devtools-core
npm i https://pkg.pr.new/TanStack/router/@tanstack/router-devtools-core@5363@tanstack/router-generator
npm i https://pkg.pr.new/TanStack/router/@tanstack/router-generator@5363@tanstack/router-plugin
npm i https://pkg.pr.new/TanStack/router/@tanstack/router-plugin@5363@tanstack/router-ssr-query-core
npm i https://pkg.pr.new/TanStack/router/@tanstack/router-ssr-query-core@5363@tanstack/router-utils
npm i https://pkg.pr.new/TanStack/router/@tanstack/router-utils@5363@tanstack/router-vite-plugin
npm i https://pkg.pr.new/TanStack/router/@tanstack/router-vite-plugin@5363@tanstack/server-functions-plugin
npm i https://pkg.pr.new/TanStack/router/@tanstack/server-functions-plugin@5363@tanstack/solid-router
npm i https://pkg.pr.new/TanStack/router/@tanstack/solid-router@5363@tanstack/solid-router-devtools
npm i https://pkg.pr.new/TanStack/router/@tanstack/solid-router-devtools@5363@tanstack/solid-start
npm i https://pkg.pr.new/TanStack/router/@tanstack/solid-start@5363@tanstack/solid-start-client
npm i https://pkg.pr.new/TanStack/router/@tanstack/solid-start-client@5363@tanstack/solid-start-server
npm i https://pkg.pr.new/TanStack/router/@tanstack/solid-start-server@5363@tanstack/start-client-core
npm i https://pkg.pr.new/TanStack/router/@tanstack/start-client-core@5363@tanstack/start-plugin-core
npm i https://pkg.pr.new/TanStack/router/@tanstack/start-plugin-core@5363@tanstack/start-server-core
npm i https://pkg.pr.new/TanStack/router/@tanstack/start-server-core@5363@tanstack/start-static-server-functions
npm i https://pkg.pr.new/TanStack/router/@tanstack/start-static-server-functions@5363@tanstack/start-storage-context
npm i https://pkg.pr.new/TanStack/router/@tanstack/start-storage-context@5363@tanstack/valibot-adapter
npm i https://pkg.pr.new/TanStack/router/@tanstack/valibot-adapter@5363@tanstack/virtual-file-routes
npm i https://pkg.pr.new/TanStack/router/@tanstack/virtual-file-routes@5363@tanstack/zod-adapter
npm i https://pkg.pr.new/TanStack/router/@tanstack/zod-adapter@5363commit:
e884da1thanks, we are also looking into async generator functions to make this even easier. so let's wait with this example, then we can showcase all of the possibilities
thanks, we are also looking into async generator functions to make this even easier. so let's wait with this example, then we can showcase all of the possibilities
Awesome! Async generator functions sound like a good solution for this problem, can't wait to see them in action.
github-actions[bot](GitHub profile, opens in a new tab) added labelsdocumentation
Actionable comments posted: 5
🧹 Nitpick comments (2)
docs/router/framework/react/guide/streaming-data-from-server-functions.md (1)
82-88: Simplify the async generator exampleWrapping each chunk in
new Promise<Message>with anasyncexecutor adds noise and encourages an anti-pattern. Yielding the message directly keeps the code focused on streaming while preserving the typing story.- for (const msg of messages) { - // Notice how we defined the type of the streamed chunks - // in the generic passed down the Promise constructor - yield new Promise<Message>(async (r) => { - // Send the message - return r(msg) - }) - } + for (const msg of messages) { + // Each yielded value remains fully typed as `Message` + yield msg + }examples/react/start-streaming-data-from-server-functions/src/routes/__root.tsx (1)
4-7: Remove unused Link importLinkisn’t referenced in this file; dropping the import keeps the example tidy.-import { - HeadContent, - Link, - Outlet, - Scripts, - createRootRoute, -} from '@tanstack/react-router' +import { + HeadContent, + Outlet, + Scripts, + createRootRoute, +} from '@tanstack/react-router'📜 Review details
Configuration used: CodeRabbit UI
Review profile: CHILL
Plan: Pro
📥 Commits
Reviewing files that changed from the base of the PR and between 31c2a5daa513cc3feea2370951c9b3694e67f943 and 6971dfa3a178cc3d3cbb7a60e08ba0437e18bbd3.
⛔ Files ignored due to path filters (2)
examples/react/start-streaming-data-from-server-functions/public/favicon.icois excluded by!**/*.icopnpm-lock.yamlis excluded by!**/pnpm-lock.yaml
📒 Files selected for processing (10)
docs/router/framework/react/guide/streaming-data-from-server-functions.md(1 hunks)docs/start/framework/react/server-functions.md(1 hunks)examples/react/start-streaming-data-from-server-functions/package.json(1 hunks)examples/react/start-streaming-data-from-server-functions/src/routeTree.gen.ts(1 hunks)examples/react/start-streaming-data-from-server-functions/src/router.tsx(1 hunks)examples/react/start-streaming-data-from-server-functions/src/routes/__root.tsx(1 hunks)examples/react/start-streaming-data-from-server-functions/src/routes/index.tsx(1 hunks)examples/react/start-streaming-data-from-server-functions/src/styles/app.css(1 hunks)examples/react/start-streaming-data-from-server-functions/tsconfig.json(1 hunks)examples/react/start-streaming-data-from-server-functions/vite.config.ts(1 hunks)
✅ Files skipped from review due to trivial changes (1)
- examples/react/start-streaming-data-from-server-functions/src/styles/app.css
🧰 Additional context used
📓 Path-based instructions (6)
**/*.{ts,tsx}
📄 CodeRabbit inference engine (AGENTS.md)
Use TypeScript in strict mode with extensive type safety across the codebase
Files:
examples/react/start-streaming-data-from-server-functions/src/router.tsxexamples/react/start-streaming-data-from-server-functions/src/routeTree.gen.tsexamples/react/start-streaming-data-from-server-functions/src/routes/__root.tsxexamples/react/start-streaming-data-from-server-functions/vite.config.tsexamples/react/start-streaming-data-from-server-functions/src/routes/index.tsx
examples/{react,solid}/**
📄 CodeRabbit inference engine (AGENTS.md)
Keep example applications under examples/react/ and examples/solid/
Files:
examples/react/start-streaming-data-from-server-functions/src/router.tsxexamples/react/start-streaming-data-from-server-functions/src/routeTree.gen.tsexamples/react/start-streaming-data-from-server-functions/tsconfig.jsonexamples/react/start-streaming-data-from-server-functions/src/routes/__root.tsxexamples/react/start-streaming-data-from-server-functions/vite.config.tsexamples/react/start-streaming-data-from-server-functions/package.jsonexamples/react/start-streaming-data-from-server-functions/src/routes/index.tsx
**/src/routes/**
📄 CodeRabbit inference engine (AGENTS.md)
Place file-based routes under src/routes/ directories
Files:
examples/react/start-streaming-data-from-server-functions/src/routes/__root.tsxexamples/react/start-streaming-data-from-server-functions/src/routes/index.tsx
docs/**/*.{md,mdx}
📄 CodeRabbit inference engine (AGENTS.md)
Use internal docs links relative to the docs/ folder (e.g., ./guide/data-loading)
Files:
docs/router/framework/react/guide/streaming-data-from-server-functions.mddocs/start/framework/react/server-functions.md
docs/{router,start}/**
📄 CodeRabbit inference engine (AGENTS.md)
Place router docs under docs/router/ and start framework docs under docs/start/
Files:
docs/router/framework/react/guide/streaming-data-from-server-functions.mddocs/start/framework/react/server-functions.md
**/package.json
📄 CodeRabbit inference engine (AGENTS.md)
Use workspace:* protocol for internal dependencies in package.json files
Files:
examples/react/start-streaming-data-from-server-functions/package.json
🧠 Learnings (2)
📚 Learning: 2025-10-01T18:31:35.420Z
Learnt from: schiller-manuel PR: TanStack/router#5330 File: e2e/react-start/custom-basepath/src/routeTree.gen.ts:58-61 Timestamp: 2025-10-01T18:31:35.420Z Learning: Do not review files named `routeTree.gen.ts` in TanStack Router repositories, as these are autogenerated files that should not be manually modified.Applied to files:
examples/react/start-streaming-data-from-server-functions/src/routeTree.gen.ts
📚 Learning: 2025-09-23T17:36:12.598Z
Learnt from: CR PR: TanStack/router#0 File: AGENTS.md:0-0 Timestamp: 2025-09-23T17:36:12.598Z Learning: Applies to **/*.{ts,tsx} : Use TypeScript in strict mode with extensive type safety across the codebaseApplied to files:
examples/react/start-streaming-data-from-server-functions/tsconfig.json
🧬 Code graph analysis (3)
examples/react/start-streaming-data-from-server-functions/src/routeTree.gen.ts (1)
examples/react/start-streaming-data-from-server-functions/src/router.tsx (1)
getRouter(4-14)
examples/react/start-streaming-data-from-server-functions/src/routes/__root.tsx (2)
examples/react/start-streaming-data-from-server-functions/src/routes/index.tsx (1)
Route(95-97)
examples/react/basic-ssr-streaming-file-based/src/routes/__root.tsx (1)
RootComponent(58-99)
examples/react/start-streaming-data-from-server-functions/src/routes/index.tsx (1)
examples/react/start-streaming-data-from-server-functions/src/routes/__root.tsx (1)
Route(13-18)
🪛 Biome (2.1.2)
examples/react/start-streaming-data-from-server-functions/src/routes/index.tsx
[error] 86-90: Promise executor functions should not be
async.(lint/suspicious/noAsyncPromiseExecutor)
🪛 markdownlint-cli2 (0.18.1)
docs/start/framework/react/server-functions.md
209-209: Spaces inside link text
(MD039, no-space-in-links)
🔇 Additional comments (8)
examples/react/start-streaming-data-from-server-functions/vite.config.ts (1)
1-17: LGTM!The Vite configuration is clean and properly structured with the correct plugin order and server settings for the TanStack Start example.
examples/react/start-streaming-data-from-server-functions/src/routes/index.tsx (6)
11-23: LGTM!The Zod schema accurately models the OpenAI streaming response format with proper typing for content, index, and finish_reason fields.
29-44: LGTM!The message generation logic correctly creates random numeric messages and validates them against the schema, ensuring type safety throughout the streaming pipeline.
58-74: LGTM!The typed ReadableStream implementation correctly demonstrates streaming
TextPartchunks with simulated latency. The type safety ensures consumers receive properly typed chunks.
105-127: LGTM!The ReadableStream reader implementation correctly handles the typed stream with proper guards and accumulates content safely.
129-137: LGTM!The async generator iteration correctly handles the typed stream and accumulates messages with proper type safety.
139-154: LGTM!The UI component properly demonstrates both streaming approaches with clear button labels and separate display areas for each method.
examples/react/start-streaming-data-from-server-functions/src/routeTree.gen.ts (1)
1-68: Skipping review of autogenerated file.This file is autogenerated by TanStack Router and should not be manually modified or reviewed. The header comments (lines 7-9) confirm this is generated content that will be overwritten.
Based on learnings
docs/start/framework/react/server-functions.md lines 207 to 213Resolvedby coderabbitai[bot](GitHub profile, opens in a new tab)@@ -204,6 +204,10 @@204204 - `setResponseHeader()` - Set custom response headers205205 - `setResponseStatus()` - Custom status codes206206207-### Streaming & Raw Responses207+### Streaming208208209-Return `Response` objects for streaming, binary data, or custom content types.209+Stream typed data from server functions to the client. See the [Streaming Data from Server Functions guide ](../guide/streaming-data-from-server-functions).210+211+### Raw Responses212+213+Return `Response` objects binary data, or custom content types.🛠️ Refactor suggestion | 🟠 Major
Clean up link text to satisfy markdownlint
There’s an extra space before the closing bracket, which violates MD039 and will keep the markdown lint step red until it’s removed.
-Stream typed data from server functions to the client. See the [Streaming Data from Server Functions guide ](../guide/streaming-data-from-server-functions). +Stream typed data from server functions to the client. See the [Streaming Data from Server Functions guide](../guide/streaming-data-from-server-functions).Based on static analysis hints.
📝 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 change207-### Streaming208-209-Stream typed data from server functions to the client. See the [Streaming Data from Server Functions guide ](../guide/streaming-data-from-server-functions).210-211-### Raw Responses212-213-Return `Response` objects binary data, or custom content types.207+### Streaming208+209+Stream typed data from server functions to the client. See the [Streaming Data from Server Functions guide](../guide/streaming-data-from-server-functions).210+211+### Raw Responses212+213+Return `Response` objects binary data, or custom content types.🧰 Tools
🪛 markdownlint-cli2 (0.18.1)
209-209: Spaces inside link text
(MD039, no-space-in-links)
🤖 Prompt for AI Agents
In docs/start/framework/react/server-functions.md around lines 207 to 213, the link text "Streaming Data from Server Functions guide " contains an extra space before the closing bracket which breaks MD039; remove the trailing space so the link reads "[Streaming Data from Server Functions guide]" and ensure there are no other stray spaces inside square brackets for links in this block.✅ Addressed in commit b5fd9ba
yes, @fulopkovacs please appyly this
Seems like the humans are having a chat. I'll hop back into my burrow for now. If you need me again, just tag @coderabbitai in a new comment, and I'll come hopping out!
Ups, okay, I applied the change 😅
@@ -0,0 +1,10 @@1+{2+ "name": "tanstack-start-streaming-data-from-server-functions",3+ "private": true,4+ "sideEffects": false,5+ "type": "module",6+ "scripts": {7+ "dev": "vite dev",8+ "build": "vite build && tsc --noEmit",9+ "start": "vite start"10+ },⚠️ Potential issue | 🔴 Critical
Fix the Vite start script
vite startis not a valid CLI entry point in Vite 7, sonpm run startwill fail. Switch tovite previewinstead."scripts": { "dev": "vite dev", "build": "vite build && tsc --noEmit", - "start": "vite start" + "start": "vite preview" },📝 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 change6- "scripts": {7- "dev": "vite dev",8- "build": "vite build && tsc --noEmit",9- "start": "vite start"10- },6+ "scripts": {7+ "dev": "vite dev",8+ "build": "vite build && tsc --noEmit",9+ "start": "vite preview"10+ },🤖 Prompt for AI Agents
examples/react/start-streaming-data-from-server-functions/package.json lines 6-10: the "start" script uses the invalid CLI command "vite start" (Vite v7); change it to use "vite preview" instead so npm run start runs the correct Vite preview server after build.@@ -0,0 +1,18 @@1+{2+ "name": "tanstack-start-streaming-data-from-server-functions",3+ "private": true,4+ "sideEffects": false,5+ "type": "module",6+ "scripts": {7+ "dev": "vite dev",8+ "build": "vite build && tsc --noEmit",9+ "start": "vite start"10+ },11+ "dependencies": {12+ "@tanstack/react-router": "^1.132.33",13+ "@tanstack/react-router-devtools": "^1.132.33",14+ "@tanstack/react-start": "^1.132.36",15+ "react": "^19.0.0",16+ "react-dom": "^19.0.0",17+ "zod": "^3.24.2"18+ },🛠️ Refactor suggestion | 🟠 Major
Use workspace protocol for internal TanStack deps
Per the repository guidelines, internal TanStack packages in examples should reference local workspaces to avoid mismatched registry installs.
- "@tanstack/react-router": "^1.132.33", - "@tanstack/react-router-devtools": "^1.132.33", - "@tanstack/react-start": "^1.132.36", + "@tanstack/react-router": "workspace:*", + "@tanstack/react-router-devtools": "workspace:*", + "@tanstack/react-start": "workspace:*",As per coding guidelines.
📝 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 change12- "@tanstack/react-router": "^1.132.33",13- "@tanstack/react-router-devtools": "^1.132.33",14- "@tanstack/react-start": "^1.132.36",15- "react": "^19.0.0",16- "react-dom": "^19.0.0",17- "zod": "^3.24.2"18- },12+ "dependencies": {13+ "@tanstack/react-router": "workspace:*",14+ "@tanstack/react-router-devtools": "workspace:*",15+ "@tanstack/react-start": "workspace:*",16+ "react": "^19.0.0",17+ "react-dom": "^19.0.0",18+ "zod": "^3.24.2"19+ },🤖 Prompt for AI Agents
In examples/react/start-streaming-data-from-server-functions/package.json around lines 12 to 18, the three internal TanStack deps (@tanstack/react-router, @tanstack/react-router-devtools, @tanstack/react-start) are pinned to registry versions; change them to use the workspace protocol (e.g. "workspace:*") so the example resolves local monorepo packages instead of installing mismatched registry versions, leave react, react-dom and zod unchanged, and run install/lockfile update afterwards.@coderabbitai all our examples use the versioned packages instead of local references since we need those examples to be runnable on its own (e.g. when using gitpick)
Seems like the humans are having a chat. I'll hop back into my burrow for now. If you need me again, just tag @coderabbitai in a new comment, and I'll come hopping out!
i mistyped, i meant you @coderabbitai
@schiller-manuel, thank you for the clarification! I apologize for the incorrect suggestion. You're absolutely right that examples need to use versioned packages to remain runnable as standalone projects (e.g., via gitpick).
I have a learning in my knowledge base that suggests using
workspace:*protocol for internal dependencies in package.json files, but it doesn't account for examples. Would you like me to:- Remove that learning entirely, or
- Keep it but add a new learning that examples should use versioned packages instead of workspace protocol?
I want to make sure I get this right for future reviews!
🧠 Learnings used
Learnt from: CR PR: TanStack/router#0 File: AGENTS.md:0-0 Timestamp: 2025-09-23T17:36:12.598Z Learning: Applies to **/package.json : Use workspace:* protocol for internal dependencies in package.json filesKeep it but add a new learning that examples should use versioned packages instead of workspace protocol?
@@ -0,0 +1,8 @@1+import { createRouter } from '@tanstack/react-router'2+import { routeTree } from './routeTree.gen'3+4+export function getRouter() {5+ const router = createRouter({6+ routeTree,7+ defaultPreload: 'intent',8+ defaultErrorComponent: (err) => <p>{err.error.stack}</p>,⚠️ Potential issue | 🟡 Minor
Consider security implications of displaying raw error stack.
Displaying
err.error.stackdirectly in the UI could expose sensitive information (file paths, internal structure, etc.) in production. For a demo/example this is acceptable, but consider adding a comment noting this should be replaced with a user-friendly error message in production.Apply this diff to add a clarifying comment:
- defaultErrorComponent: (err) => <p>{err.error.stack}</p>, + // Note: In production, avoid displaying raw stack traces to users + defaultErrorComponent: (err) => <p>{err.error.stack}</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 change8- defaultErrorComponent: (err) => <p>{err.error.stack}</p>,8+ // Note: In production, avoid displaying raw stack traces to users9+ defaultErrorComponent: (err) => <p>{err.error.stack}</p>,🤖 Prompt for AI Agents
In examples/react/start-streaming-data-from-server-functions/src/router.tsx around line 8, the defaultErrorComponent currently renders err.error.stack directly which can leak sensitive internals; add an inline comment above or next to this line noting that showing raw error stacks is only acceptable in demos and must be replaced in production with a generic/user-friendly message (and consider logging the full stack server-side instead).@coderabbitai this is just a demo, not a production app, so ignore this
@schiller-manuel, you're absolutely right! I understand this is a demo example, and displaying the raw error stack is perfectly appropriate for educational purposes. I'll make a note of this for future reviews of example code. Thank you for the clarification!
✏️ Learnings added
Learnt from: schiller-manuel PR: TanStack/router#5363 File: examples/react/start-streaming-data-from-server-functions/src/router.tsx:8-8 Timestamp: 2025-10-05T20:43:54.644Z Learning: For code in example or demo directories (e.g., paths containing `examples/`), do not flag production-level security concerns such as displaying raw error stacks, hardcoded credentials for demos, or lack of input validation. Examples are for educational purposes and different standards apply.Note: Learnings are effective only in the context of similar code segments. To apply general coding guidelines, please configure review instructions. You can manage existing learnings in the app.
examples/react/start-streaming-data-from-server-functions/src/routes/index.tsx lines 80 to 89Resolvedby coderabbitai[bot](GitHub profile, opens in a new tab)@@ -0,0 +73,21 @@73+ return stream74+})75+76+/**77+ You can also use an async generator function to stream78+ typed chunks to the client.79+*/80+const streamingWithAnAsyncGeneratorFn = createServerFn().handler(81+ async function* () {82+ const messages = generateMessages()83+ for (const msg of messages) {84+ // Notice how we defined the type of the streamed chunks85+ // in the generic passed down the Promise constructor86+ yield new Promise<TextPart>(async (r) => {87+ // simulate network latency88+ await sleep(500)89+ return r(msg)90+ })91+ }92+ },93+)⚠️ Potential issue | 🟠 Major
Fix the async promise executor anti-pattern.
The static analysis tool correctly flagged lines 86-90. Using an async function as a Promise executor is an anti-pattern because:
- The async executor's implicit promise is ignored
- Rejections in async executors can be swallowed
- The pattern unnecessarily complicates the control flow
Apply this diff to simplify the async generator:
const streamingWithAnAsyncGeneratorFn = createServerFn().handler( async function* () { const messages = generateMessages() for (const msg of messages) { - // Notice how we defined the type of the streamed chunks - // in the generic passed down the Promise constructor - yield new Promise<TextPart>(async (r) => { - // simulate network latency - await sleep(500) - return r(msg) - }) + // simulate network latency + await sleep(500) + // Notice how TypeScript infers the yielded type + yield msg } }, )📝 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 change80-const streamingWithAnAsyncGeneratorFn = createServerFn().handler(81- async function* () {82- const messages = generateMessages()83- for (const msg of messages) {84- // Notice how we defined the type of the streamed chunks85- // in the generic passed down the Promise constructor86- yield new Promise<TextPart>(async (r) => {87- // simulate network latency88- await sleep(500)89- return r(msg)80+const streamingWithAnAsyncGeneratorFn = createServerFn().handler(81+ async function* () {82+ const messages = generateMessages()83+ for (const msg of messages) {84+ // simulate network latency85+ await sleep(500)86+ // Notice how TypeScript infers the yielded type87+ yield msg88+ }89+ },90+)🧰 Tools
🪛 Biome (2.1.2)
[error] 86-90: Promise executor functions should not be
async.(lint/suspicious/noAsyncPromiseExecutor)
🤖 Prompt for AI Agents
In examples/react/start-streaming-data-from-server-functions/src/routes/index.tsx around lines 80 to 93, the Promise executor is declared async (lines ~86-90), which is an anti-pattern because its implicit promise is ignored and rejections can be swallowed; fix it by removing the async executor and simplifying the generator: either await sleep(500) then yield the plain msg directly inside the loop, or if you need a Promise wrapper use a non-async executor that resolves via setTimeout (i.e., create Promise<TextPart>((resolve) => setTimeout(() => resolve(msg), 500))). Ensure no async function is passed as the Promise executor.✅ Addressed in commits 15b3d3a to c80eceb
this sounds reasonable, please apply this
@schiller-manuel I understand you'd like this fix applied. However, I'm unable to commit code directly to the repository. Here's the corrected code that you or the PR author can apply:
Current code (lines 79-92):
const streamingWithAnAsyncGeneratorFn = createServerFn().handler( async function* () { const messages = generateMessages() for (const msg of messages) { // Notice how we defined the type of the streamed chunks // in the generic passed down the Promise constructor yield new Promise<TextPart>(async (r) => { // simulate network latency await sleep(500) return r(msg) }) } }, )Corrected code:
const streamingWithAnAsyncGeneratorFn = createServerFn().handler( async function* () { const messages = generateMessages() for (const msg of messages) { // simulate network latency await sleep(500) // Notice how TypeScript infers the yielded type yield msg } }, )This fix:
- Removes the async Promise executor anti-pattern
- Simplifies the code by directly yielding the message after awaiting sleep
- Maintains the same functionality and type safety
- Resolves the Biome linting error
The PR author (@fulopkovacs) can apply this change directly in the file
examples/react/start-streaming-data-from-server-functions/src/routes/index.tsx.Good catch, I applied the fix: 15b3d3abb
Seems like the humans are having a chat. I'll hop back into my burrow for now. If you need me again, just tag @coderabbitai in a new comment, and I'll come hopping out!
thanks a lot!
Sign in to join this conversation.
View your CI Pipeline Execution ↗ for commit e884da1ed629a257ace99a92b5354cdc734ca636
nx affected --targets=test:eslint,test:unit,tes...nx run-many --target=build --exclude=examples/*...☁️ Nx Cloud last updated this comment at
2025-10-05 23:01:59UTC