Skip to content

Conversation

@schiller-manuel
Copy link
Contributor

@schiller-manuel schiller-manuel commented Jan 7, 2026

Summary by CodeRabbit

  • New Features

    • Per-call custom fetch support for server functions and middleware, with call-site override precedence.
    • Demo page showcasing custom-fetch scenarios and interactive verification tests.
  • UI

    • Added navigation link to the custom-fetch demo from the home route.
  • Tests

    • Added end-to-end tests for direct, middleware, chained, override, and default-fetch behaviors.
  • Documentation

    • Expanded middleware guide with header merging, fetch precedence, and examples.

✏️ Tip: You can customize this high-level summary in your review settings.

@coderabbitai
Copy link
Contributor

coderabbitai bot commented Jan 7, 2026

📝 Walkthrough

Walkthrough

Adds per-call CustomFetch support and threads optional fetch overrides through client RPC, middleware, and server-fn plumbing. Adds a /custom-fetch file route with component, middleware, server functions, E2E tests, and updates generated route tree and public type exports to include CustomFetch and the new route.

Changes

Cohort / File(s) Summary
Route Tree Generation
e2e/react-start/server-functions/src/routeTree.gen.ts
Generated route tree updated to include new /custom-fetch route and expose CustomFetchRoute in root children and route maps.
New Route Implementation
e2e/react-start/server-functions/src/routes/custom-fetch.tsx, e2e/react-start/server-functions/src/routes/index.tsx
Added /custom-fetch file route with server functions, middleware, component UI/tests; added home nav link to route.
E2E Tests
e2e/react-start/server-functions/tests/server-functions.spec.ts
Added Playwright tests covering direct per-call fetch, middleware-provided fetch, chained middleware override, direct override of middleware, and default fetch (note: duplicate insertion present in diff).
RPC Layer
packages/start-client-core/src/client-rpc/serverFnFetcher.ts
Supports optional per-call fetch override: uses first-arg fetch when provided, otherwise falls back to handler.
Core Server-Fn Types & Middleware
packages/start-client-core/src/createServerFn.ts, packages/start-client-core/src/createMiddleware.ts
Introduced CustomFetch type export; added optional fetch?: CustomFetch and internal _callSiteFetch?: CustomFetch across fetcher, middleware, and context payloads; propagate fetch through middleware execution.
Public Exports & Tests
packages/start-client-core/src/index.tsx, packages/start-client-core/src/tests/*.test-d.ts
Exported CustomFetch publicly; updated type tests and assertions to include optional fetch?: CustomFetch.
Docs
docs/start/framework/react/guide/middleware.md
Expanded middleware docs with header merging, fetch precedence, call-site override examples, and SSR notes.

Sequence Diagram(s)

sequenceDiagram
  autonumber
  participant Client
  participant RPC as serverFnFetcher
  participant Middleware as MiddlewareChain
  participant Server as ServerFunction

  Note over Client,RPC: Call-site may pass an optional fetch
  Client->>RPC: invoke serverFn(payload, opts{ fetch? })
  RPC->>Middleware: deliver payload including _callSiteFetch/fetch
  alt Middleware modifies fetch
    Middleware->>Middleware: set/override ctx.fetch
  end
  Middleware->>Server: call handler with ctx (ctx.fetch prioritized)
  Server->>Server: perform fetch using resolved fetch impl
  Server-->>Client: return response
Loading

Estimated code review effort

🎯 3 (Moderate) | ⏱️ ~20 minutes

Possibly related PRs

Suggested labels

documentation

Suggested reviewers

  • chorobin
  • birkskyum

Poem

"I hop a header, swift and neat,
A fetch that travels from seat to seat.
Middleware whispers, chains that try,
Call-site shouts — the strongest fly.
My route delights — fetches meet!" 🐰

🚥 Pre-merge checks | ✅ 2 | ❌ 1
❌ Failed checks (1 warning)
Check name Status Explanation Resolution
Docstring Coverage ⚠️ Warning Docstring coverage is 20.00% which is insufficient. The required threshold is 80.00%. Write docstrings for the functions missing them to satisfy the coverage threshold.
✅ 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 'feat: allow custom fetch impl for server functions' accurately describes the main feature addition: enabling custom fetch implementations for server functions.

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


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

@nx-cloud
Copy link

nx-cloud bot commented Jan 7, 2026

View your CI Pipeline Execution ↗ for commit 58d101f

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

☁️ Nx Cloud last updated this comment at 2026-01-08 00:17:26 UTC

@pkg-pr-new
Copy link

pkg-pr-new bot commented Jan 7, 2026

More templates

@tanstack/arktype-adapter

npm i https://pkg.pr.new/TanStack/router/@tanstack/arktype-adapter@6327

@tanstack/eslint-plugin-router

npm i https://pkg.pr.new/TanStack/router/@tanstack/eslint-plugin-router@6327

@tanstack/history

npm i https://pkg.pr.new/TanStack/router/@tanstack/history@6327

@tanstack/nitro-v2-vite-plugin

npm i https://pkg.pr.new/TanStack/router/@tanstack/nitro-v2-vite-plugin@6327

@tanstack/react-router

npm i https://pkg.pr.new/TanStack/router/@tanstack/react-router@6327

@tanstack/react-router-devtools

npm i https://pkg.pr.new/TanStack/router/@tanstack/react-router-devtools@6327

@tanstack/react-router-ssr-query

npm i https://pkg.pr.new/TanStack/router/@tanstack/react-router-ssr-query@6327

@tanstack/react-start

npm i https://pkg.pr.new/TanStack/router/@tanstack/react-start@6327

@tanstack/react-start-client

npm i https://pkg.pr.new/TanStack/router/@tanstack/react-start-client@6327

@tanstack/react-start-server

npm i https://pkg.pr.new/TanStack/router/@tanstack/react-start-server@6327

@tanstack/router-cli

npm i https://pkg.pr.new/TanStack/router/@tanstack/router-cli@6327

@tanstack/router-core

npm i https://pkg.pr.new/TanStack/router/@tanstack/router-core@6327

@tanstack/router-devtools

npm i https://pkg.pr.new/TanStack/router/@tanstack/router-devtools@6327

@tanstack/router-devtools-core

npm i https://pkg.pr.new/TanStack/router/@tanstack/router-devtools-core@6327

@tanstack/router-generator

npm i https://pkg.pr.new/TanStack/router/@tanstack/router-generator@6327

@tanstack/router-plugin

npm i https://pkg.pr.new/TanStack/router/@tanstack/router-plugin@6327

@tanstack/router-ssr-query-core

npm i https://pkg.pr.new/TanStack/router/@tanstack/router-ssr-query-core@6327

@tanstack/router-utils

npm i https://pkg.pr.new/TanStack/router/@tanstack/router-utils@6327

@tanstack/router-vite-plugin

npm i https://pkg.pr.new/TanStack/router/@tanstack/router-vite-plugin@6327

@tanstack/solid-router

npm i https://pkg.pr.new/TanStack/router/@tanstack/solid-router@6327

@tanstack/solid-router-devtools

npm i https://pkg.pr.new/TanStack/router/@tanstack/solid-router-devtools@6327

@tanstack/solid-router-ssr-query

npm i https://pkg.pr.new/TanStack/router/@tanstack/solid-router-ssr-query@6327

@tanstack/solid-start

npm i https://pkg.pr.new/TanStack/router/@tanstack/solid-start@6327

@tanstack/solid-start-client

npm i https://pkg.pr.new/TanStack/router/@tanstack/solid-start-client@6327

@tanstack/solid-start-server

npm i https://pkg.pr.new/TanStack/router/@tanstack/solid-start-server@6327

@tanstack/start-client-core

npm i https://pkg.pr.new/TanStack/router/@tanstack/start-client-core@6327

@tanstack/start-fn-stubs

npm i https://pkg.pr.new/TanStack/router/@tanstack/start-fn-stubs@6327

@tanstack/start-plugin-core

npm i https://pkg.pr.new/TanStack/router/@tanstack/start-plugin-core@6327

@tanstack/start-server-core

npm i https://pkg.pr.new/TanStack/router/@tanstack/start-server-core@6327

@tanstack/start-static-server-functions

npm i https://pkg.pr.new/TanStack/router/@tanstack/start-static-server-functions@6327

@tanstack/start-storage-context

npm i https://pkg.pr.new/TanStack/router/@tanstack/start-storage-context@6327

@tanstack/valibot-adapter

npm i https://pkg.pr.new/TanStack/router/@tanstack/valibot-adapter@6327

@tanstack/virtual-file-routes

npm i https://pkg.pr.new/TanStack/router/@tanstack/virtual-file-routes@6327

@tanstack/vue-router

npm i https://pkg.pr.new/TanStack/router/@tanstack/vue-router@6327

@tanstack/vue-router-devtools

npm i https://pkg.pr.new/TanStack/router/@tanstack/vue-router-devtools@6327

@tanstack/vue-router-ssr-query

npm i https://pkg.pr.new/TanStack/router/@tanstack/vue-router-ssr-query@6327

@tanstack/vue-start

npm i https://pkg.pr.new/TanStack/router/@tanstack/vue-start@6327

@tanstack/vue-start-client

npm i https://pkg.pr.new/TanStack/router/@tanstack/vue-start-client@6327

@tanstack/vue-start-server

npm i https://pkg.pr.new/TanStack/router/@tanstack/vue-start-server@6327

@tanstack/zod-adapter

npm i https://pkg.pr.new/TanStack/router/@tanstack/zod-adapter@6327

commit: 58d101f

@github-actions github-actions bot added the documentation Everything documentation related label Jan 7, 2026
Copy link
Contributor

@coderabbitai coderabbitai bot left a comment

Choose a reason for hiding this comment

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

Actionable comments posted: 0

🧹 Nitpick comments (1)
docs/start/framework/react/guide/middleware.md (1)

545-545: Minor wording refinement.

Per static analysis, "merged together" can be simplified to "merged" for conciseness while retaining clarity.

✏️ Proposed wording refinement
- When multiple middlewares set headers, they are **merged together**. Later middlewares can add new headers or override headers set by earlier middlewares:
+ When multiple middlewares set headers, they are **merged**. Later middlewares can add new headers or override headers set by earlier middlewares:
📜 Review details

Configuration used: defaults

Review profile: CHILL

Plan: Pro

📥 Commits

Reviewing files that changed from the base of the PR and between aa7aadc and 58d101f.

📒 Files selected for processing (1)
  • docs/start/framework/react/guide/middleware.md
🧰 Additional context used
📓 Path-based instructions (1)
docs/**/*.{md,mdx}

📄 CodeRabbit inference engine (AGENTS.md)

Use relative links to docs/ folder format (e.g., ./guide/data-loading) for internal documentation references

Files:

  • docs/start/framework/react/guide/middleware.md
🪛 LanguageTool
docs/start/framework/react/guide/middleware.md

[style] ~523-~523: Consider using a different adverb to strengthen your wording.
Context: ...ses the client method executes in a completely different client-side context than se...

(COMPLETELY_ENTIRELY)


[style] ~545-~545: ‘merged together’ might be wordy. Consider a shorter alternative.
Context: ...ple middlewares set headers, they are merged together. Later middlewares can add new header...

(EN_WORDINESS_PREMIUM_MERGED_TOGETHER)

⏰ Context from checks skipped due to timeout of 90000ms. You can increase the timeout in your CodeRabbit configuration to a maximum of 15 minutes (900000ms). (2)
  • GitHub Check: Test
  • GitHub Check: Preview
🔇 Additional comments (1)
docs/start/framework/react/guide/middleware.md (1)

525-720: Comprehensive and well-structured documentation for custom fetch and header handling.

The new sections introduce client-side request modification clearly, with well-organized subsections on headers, custom fetch, and precedence rules. The examples progress logically from simple to complex (single middleware, call-site override, chained middlewares), and the precedence tables effectively communicate priority order. The SSR caveat (line 718-719) is appropriately highlighted to prevent common misunderstandings.

I see the documentation imports CustomFetch from '@tanstack/react-start' (lines 605, 627). Please verify this type is exported from the public API surface of the package, as indicated in the PR summary.

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

Labels

documentation Everything documentation related package: start-client-core

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants