Skip to content

Conversation

@schiller-manuel
Copy link
Contributor

@schiller-manuel schiller-manuel commented Nov 22, 2025

fixes: #5872

Summary by CodeRabbit

  • Refactor

    • HTTP method is now provided on the server function context (access via context.method); handler signatures no longer receive method as a separate parameter.
    • Simplified server function type signatures by removing the per-method generic.
  • Style

    • Adjusted type formatting and string literal quoting for consistency.
  • Tests

    • Updated test assertions to match the new context shape.

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

@coderabbitai
Copy link
Contributor

coderabbitai bot commented Nov 22, 2025

Walkthrough

Removes the per-method generic and method property from ServerFn types, moves request method retrieval into middleware via getRequest(), updates handlers to read context.method, and adjusts tests and e2e expectations to reflect middleware-propagated method in context.

Changes

Cohort / File(s) Summary
Factory server handlers
e2e/react-start/server-functions/src/routes/factory/-functions/createFooServerFn.ts, e2e/solid-start/server-functions/src/routes/factory/-functions/createFooServerFn.ts
Add getRequest() usage in middleware, extend emitted context with method: request.method, and update handler signature to remove method parameter and read context.method.
Factory test expectations
e2e/react-start/server-functions/src/routes/factory/index.tsx, e2e/solid-start/server-functions/src/routes/factory/index.tsx
Update expected context objects in tests to include method (e.g., 'GET' or 'POST') and adjust formatting of expected payloads.
Core server-fn types & implementation
packages/start-client-core/src/createServerFn.ts, packages/start-client-core/src/tests/createServerFn.test-d.ts
Remove TMethod generic and method property from ServerFn / ServerFnCtx types; update builder option merge logic and adjust type tests to remove hard-coded method expectations.
Ambient/type formatting
e2e/solid-start/basic-cloudflare/worker-configuration.d.ts
Cosmetic/type formatting changes: switch string literal quotes and expand mapped type to multiline form; no behavioral change.

Sequence Diagram(s)

sequenceDiagram
    participant Req as HTTP Request
    participant Middleware as ServerFn Middleware
    participant Handler as ServerFn Handler
    Note over Req,Middleware: New flow — method sourced at runtime
    Req->>Middleware: incoming request
    Middleware->>Middleware: call getRequest() -> request.method
    Middleware->>Handler: invoke with context + { method: request.method }
    Handler->>Handler: reads context.method at runtime
Loading

Estimated code review effort

🎯 4 (Complex) | ⏱️ ~45 minutes

  • Areas needing extra attention:
    • packages/start-client-core/src/createServerFn.ts — public type signature change and builder option merge behavior.
    • E2E test files under e2e/*/server-functions/* — ensure runtime propagation of method matches expectations.
    • packages/start-client-core/src/tests/createServerFn.test-d.ts — type assertion updates reflecting removed method generic.

Possibly related PRs

Suggested reviewers

  • chorobin

Poem

🐰 Hopping through middleware, I sniff the method trail,

I fetch the request, pass context along the trail.
No generic to bind, context carries the key,
Handlers read their method — simple, tidy, and free.
A little rabbit clap — refactor complete, huzzah! 🎉

Pre-merge checks and finishing touches

✅ Passed checks (5 passed)
Check name Status Explanation
Description Check ✅ Passed Check skipped - CodeRabbit’s high-level summary is enabled.
Title check ✅ Passed The title clearly and specifically describes the main fix: allowing method override for server functions when using factories.
Linked Issues check ✅ Passed The PR addresses issue #5872 by removing method from ServerFnCtx type and propagating it through middleware context instead, enabling proper method override in chained factories.
Out of Scope Changes check ✅ Passed All changes are directly scoped to fixing the method override issue: core type updates, test updates, and e2e examples updated consistently. No unrelated changes detected.
Docstring Coverage ✅ Passed No functions found in the changed files to evaluate docstring coverage. Skipping docstring coverage check.
✨ Finishing touches
  • 📝 Generate docstrings
🧪 Generate unit tests (beta)
  • Create PR with unit tests
  • Post copyable unit tests in a comment
  • Commit unit tests in branch fix-5872

📜 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 b44f487 and fcfc8c8.

📒 Files selected for processing (3)
  • e2e/solid-start/basic-cloudflare/worker-configuration.d.ts (1 hunks)
  • e2e/solid-start/server-functions/src/routes/factory/-functions/createFooServerFn.ts (1 hunks)
  • e2e/solid-start/server-functions/src/routes/factory/index.tsx (7 hunks)
🚧 Files skipped from review as they are similar to previous changes (1)
  • e2e/solid-start/basic-cloudflare/worker-configuration.d.ts
🧰 Additional context used
🧠 Learnings (1)
📚 Learning: 2025-10-08T08:11:47.088Z
Learnt from: nlynzaad
Repo: TanStack/router PR: 5402
File: packages/router-generator/tests/generator/no-formatted-route-tree/routeTree.nonnested.snapshot.ts:19-21
Timestamp: 2025-10-08T08:11:47.088Z
Learning: Test snapshot files in the router-generator tests directory (e.g., files matching the pattern `packages/router-generator/tests/generator/**/routeTree*.snapshot.ts` or `routeTree*.snapshot.js`) should not be modified or have issues flagged, as they are fixtures used to verify the generator's output and are intentionally preserved as-is.

Applied to files:

  • e2e/solid-start/server-functions/src/routes/factory/index.tsx
🧬 Code graph analysis (2)
e2e/solid-start/server-functions/src/routes/factory/index.tsx (1)
e2e/solid-start/server-functions/src/routes/factory/-functions/functions.ts (1)
  • composedFn (86-93)
e2e/solid-start/server-functions/src/routes/factory/-functions/createFooServerFn.ts (1)
packages/start-server-core/src/request-response.ts (1)
  • getRequest (72-75)
⏰ 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 (5)
e2e/solid-start/server-functions/src/routes/factory/-functions/createFooServerFn.ts (3)

2-2: LGTM! Import statement is correct.

The import of getRequest is properly sourced from @tanstack/solid-start/server and aligns with the PR's objective to retrieve the request method within middleware.


6-9: Core fix implemented correctly.

The middleware now properly captures the request method from getRequest() and propagates it through the context. This directly addresses the issue where method: "POST" was being ignored in server function factories.


17-18: Handler correctly updated to use context-based method.

The handler signature and logging statement have been properly updated to access the method from context rather than as a separate parameter, maintaining consistency with the middleware changes.

e2e/solid-start/server-functions/src/routes/factory/index.tsx (2)

42-42: Test expectations correctly updated with method field.

The expected context values now properly include the method field with appropriate values: 'GET' for standard functions and 'POST' for functions suffixed with "POST". This aligns with the middleware changes that propagate method through context.

Also applies to: 51-51, 60-60, 69-69, 78-78


87-93: Test expectations updated with improved formatting.

The context objects have been expanded to multi-line format and updated to include the method field. The formatting change improves readability for these more complex context objects, and the method values correctly match the function naming convention (POST suffix = 'POST' method, otherwise 'GET').

Also applies to: 102-108, 116-122


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

@nx-cloud
Copy link

nx-cloud bot commented Nov 22, 2025

View your CI Pipeline Execution ↗ for commit fcfc8c8

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

☁️ Nx Cloud last updated this comment at 2025-11-22 09:47:55 UTC

@pkg-pr-new
Copy link

pkg-pr-new bot commented Nov 22, 2025

More templates

@tanstack/arktype-adapter

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

@tanstack/directive-functions-plugin

npm i https://pkg.pr.new/TanStack/router/@tanstack/directive-functions-plugin@5938

@tanstack/eslint-plugin-router

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

@tanstack/history

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

@tanstack/nitro-v2-vite-plugin

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

@tanstack/react-router

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

@tanstack/react-router-devtools

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

@tanstack/react-router-ssr-query

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

@tanstack/react-start

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

@tanstack/react-start-client

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

@tanstack/react-start-server

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

@tanstack/router-cli

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

@tanstack/router-core

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

@tanstack/router-devtools

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

@tanstack/router-devtools-core

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

@tanstack/router-generator

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

@tanstack/router-plugin

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

@tanstack/router-ssr-query-core

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

@tanstack/router-utils

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

@tanstack/router-vite-plugin

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

@tanstack/server-functions-plugin

npm i https://pkg.pr.new/TanStack/router/@tanstack/server-functions-plugin@5938

@tanstack/solid-router

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

@tanstack/solid-router-devtools

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

@tanstack/solid-router-ssr-query

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

@tanstack/solid-start

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

@tanstack/solid-start-client

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

@tanstack/solid-start-server

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

@tanstack/start-client-core

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

@tanstack/start-plugin-core

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

@tanstack/start-server-core

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

@tanstack/start-static-server-functions

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

@tanstack/start-storage-context

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

@tanstack/valibot-adapter

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

@tanstack/virtual-file-routes

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

@tanstack/zod-adapter

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

commit: fcfc8c8

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)
e2e/solid-start/basic-cloudflare/worker-configuration.d.ts (1)

16-17: ProcessEnv narrowing is fine; flag if you need widening later.

Extending StringifyValues keeps process.env.MY_VAR typed as the literal 'Hello from Cloudflare' (a subtype of string). If any consumer needs a plain string, use const v: string = process.env.MY_VAR or String(process.env.MY_VAR).

📜 Review details

Configuration used: CodeRabbit UI

Review profile: CHILL

Plan: Pro

📥 Commits

Reviewing files that changed from the base of the PR and between ab676cb and b44f487.

📒 Files selected for processing (5)
  • e2e/react-start/server-functions/src/routes/factory/-functions/createFooServerFn.ts (1 hunks)
  • e2e/react-start/server-functions/src/routes/factory/index.tsx (7 hunks)
  • e2e/solid-start/basic-cloudflare/worker-configuration.d.ts (1 hunks)
  • packages/start-client-core/src/createServerFn.ts (2 hunks)
  • packages/start-client-core/src/tests/createServerFn.test-d.ts (0 hunks)
💤 Files with no reviewable changes (1)
  • packages/start-client-core/src/tests/createServerFn.test-d.ts
🧰 Additional context used
🧬 Code graph analysis (2)
e2e/react-start/server-functions/src/routes/factory/index.tsx (1)
e2e/solid-start/server-functions/src/routes/factory/-functions/functions.ts (1)
  • composedFn (86-93)
e2e/react-start/server-functions/src/routes/factory/-functions/createFooServerFn.ts (2)
packages/start-server-core/src/request-response.ts (1)
  • getRequest (72-75)
packages/start-client-core/src/createServerFn.ts (1)
  • createServerFn (49-168)
⏰ 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: Preview
  • GitHub Check: Test
🔇 Additional comments (7)
e2e/solid-start/basic-cloudflare/worker-configuration.d.ts (2)

5-7: LGTM: keep MY_VAR as a string literal type.

Single-quoted literal is equivalent; type remains narrowed to 'Hello from Cloudflare'. No runtime impact.


11-14: Formatting-only change.

Mapped type split over lines; no semantic changes. Good to keep.

e2e/react-start/server-functions/src/routes/factory/-functions/createFooServerFn.ts (2)

2-9: Middleware now correctly exposes HTTP method via context

Importing getRequest and wiring request.method into context in the server middleware is a good fit for the new API surface: handlers can now reliably read the actual HTTP verb via context.method, and the e2e factory tests will fail if the underlying request method doesn’t change as expected when overriding method on factories.

Please ensure the React Start server-functions E2E suite (/factory route) is run so we catch any regressions in environments where getRequest() might not be available.


17-18: Handler correctly switches from method param to context.method

Updating the handler to destructure only { context } and read context.method aligns with the new ServerFnCtx shape and the middleware-provided context, avoiding reliance on a top-level ctx.method while still surfacing the HTTP verb to the user code.

Double-check any other handlers in this E2E app that previously used a method parameter to ensure they are also migrated to context.method where appropriate.

e2e/react-start/server-functions/src/routes/factory/index.tsx (1)

40-122: Updated expectations correctly assert context.method across factory-based serverFns

The expanded expected.context objects for all serverFns (foo*, bar*, local*, composedFn) consistently include a method field that matches the intended HTTP verb ('GET' for default functions, 'POST' for *POST variants) alongside the accumulated middleware context fields. This tightly couples the E2E surface to the new behavior: if method overriding via factories ever regresses, these tests will immediately fail via mismatched context.method.

Ensure the corresponding Solid Start factory tests stay in sync with this expectation pattern so both runtimes validate method propagation in the same way.

packages/start-client-core/src/createServerFn.ts (2)

161-165: Option merge in fun correctly fixes method overriding for factories

Building newOptions = { ...resolvedOptions, ...options } and passing it as __opts into createServerFn ensures that per-call overrides (especially method) win over the factory’s base configuration, even when the factory itself was produced by earlier middleware()/inputValidator() chaining. This directly addresses the “factories ignore { method: 'POST' } at runtime” issue while preserving existing behavior for other options.

Please run the factory-focused serverFn tests (including those creating nested factories) to confirm that method now reflects the latest override in both the client fetcher and the server-side request.


315-322: ServerFnCtx now reflects only data/context/signal; method moves into middleware-derived context

Updating ServerFn to accept ServerFnCtx<TRegister, TMiddlewares, TInputValidator> and redefining ServerFnCtx as { data; context; signal } removes method from the top-level ctx type, pushing HTTP method awareness into the composed context (e.g., via middleware injecting context.method). This matches the E2E usage and keeps the core handler ctx minimal, while ServerFnMiddlewareOptions.method still carries the verb for middleware chains.

Verify that any remaining handlers or type tests that previously accessed ctx.method have been updated (or intentionally left) to use context.method or middleware-level typing as appropriate.

@schiller-manuel schiller-manuel merged commit 2fd4cba into main Nov 22, 2025
6 checks passed
@schiller-manuel schiller-manuel deleted the fix-5872 branch November 22, 2025 09:53
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Creating reusable server functions ignores setting the method: "GET" | "POST"

2 participants