How should loader cancellation propagate into createServerFn handlers? #11081
Replies: 1 comment
-
|
TanStack’s own React Start E2E fixture currently uses this exact pattern: import { getRequest } from "@tanstack/react-start/server"
const getReport = createServerFn().handler(async () => {
const { signal } = getRequest()
return fetch("https://example.com/report", { signal })
})The relevant fixture reads Function middleware also exposes a typed The important distinction is that cancellation is propagated, not magically applied to every downstream task:
So for a loader, passing |
Beta Was this translation helpful? Give feedback.
Uh oh!
There was an error while loading. Please reload this page.
-
TanStack Router loaders receive an
AbortSignal, andcreateServerFncallers also acceptsignal:However, the signal is not exposed in the typed
.handler(({ data }) => {})context.Should the handler use
getRequest().signal, or is middleware the supported way to access it? Also, during SSR and client navigation, does cancellation stop only the RPC request, or does it notify the running server handler so downstream database/API work can be cancelled?Docs: [Server Functions – Request Cancellation](https://tanstack.com/start/latest/docs/framework/react/guide/server-functions#request-cancellation)
Beta Was this translation helpful? Give feedback.
All reactions