[Start] `setResponseStatus` in a server fn called by a loader during SSR becomes the HTML document's status (since 1.169.0)
Los mantenedores suelen responder en 1 día
@adityareddy-dev ya está trabajando en esto.
Desde el 4/11/2026.
- #8864 de @adityareddy-dev — abierto
Evaluación
- Dificultad
- 4/5
- Tiempo estimado
- 3-5 días
- Aptitud para principiantes
- 45/100
- Tipo de issue
- Error
- Claridad
- Bien especificado
- Estado de actividad
- Activo
- Stack tecnológico
- playwright, react, typescript, vite
Línea de trabajo
Start with the named response-state flow in internal-request-response.js (setResponseStatus and applyResponseState), then trace the in-process call in createSsrRpc.js and document finalization in createStartHandler.js. Run the linked reproducer with pnpm i && pnpm test to establish the current behavior. Done means SSR document requests retain the router's status while client RPC responses still use the status set by the server function.
Escrito por el modelo de indexación a partir del texto del issue.
Descripción
Which project does this relate to?
Start
Describe the bug
A server fn sets a status for its RPC caller, for example setResponseStatus(503) when an upstream is down, and returns a fallback value (or throws, and the loader catches). When a route loader calls that fn during SSR, the fn runs in the document request's context, and the status it set replaces the document's status. The page renders its fallback correctly but is served as 503.
export const getItem = createServerFn({ method: 'GET' })
.validator((id: string) => id)
.handler(({ data: id }) => {
setResponseStatus(503)
return { ok: false, id }
})
export const Route = createFileRoute('/items/$id')({
loader: ({ params }) => getItem({ data: params.id }),
component: Item,
})
On a client navigation the RPC answers 503, which is what the fn intends. On a full page load, GET /items/1 answers 503 with a fully rendered page.
The same thing happens when the fn throws after setResponseStatus(503) and the loader catches the error. Response headers set by the fn (for example cache-control) also reach the document. That is probably wanted for setCookie, so this report is about the status.
This is a regression. @tanstack/react-start 1.168.60 (start-server-core 1.169.39) answers 200. 1.169.0 (start-server-core 1.169.41, which shipped #7588) and 1.169.4 answer 503.
Complete minimal reproducer
https://github.com/Tarekkharsa/tanstack-start-server-fn-status
Steps to Reproduce the Bug
pnpm i && pnpm test- The test builds, runs
vite previewon port 7311, fetches/items/1and/caught/1, then clicks the same routes in Chromium to record the RPC status. It exits 1 when a document is not 200.
Output:
SSR document requests (a route loader calls a server fn that sets 503):
FAIL GET /items/1 -> HTTP 503 (expected 200); fallback rendered: true
FAIL GET /caught/1 -> HTTP 503 (expected 200); fallback rendered: true
Client navigation (the same server fn called as an RPC):
info /items/1: RPC /_serverFn/8804e69444d5c... -> HTTP 503 (503 is intended here)
info /caught/1: RPC /_serverFn/5863b083327b3... -> HTTP 503 (503 is intended here)
2/2 documents answered with the server fn's status instead of 200
Expected behavior
A status set by a server fn applies to that fn's own RPC response. When a loader calls the fn in-process during SSR, the document keeps the status the router decides (200 here, or 404 from notFound(), and so on).
Screenshots or Videos
n/a
Platform
- Router / Start Version:
@tanstack/react-start1.169.4,@tanstack/start-server-core1.169.45,@tanstack/react-router1.170.46,@tanstack/router-core1.171.39 - React: 19.3.1
- OS: macOS 27.0
- Node: 24.22.1
- Browser: Chromium 156 (Playwright 1.64.1), only for the RPC half of the test
- Bundler: vite
- Bundler Version: 8.3.5
Additional context
Where it happens, in the published @tanstack/[email protected] dist/esm:
internal-request-response.js:449-453: oneeventper incoming request, run witheventStorage.run(event, ...).internal-request-response.js:715-726:setResponseStatuswritesgetResponseState(event).statuson that event.createSsrRpc.js:8: during SSR the fn runs in-process throughgetServerFnById(id, { origin: 'server' }), inside the same event.createStartHandler.js:500: the document goes throughfinalizeResponse(response, event), andapplyResponseState(internal-request-response.js:255-279) sendshelperStatus ?? response.status.
So the fn's status lands on the document. The RPC path reads the same state through getSerializedResponseState() (server-functions-handler.js:331), which is the intended use.
Possible fixes:
-
When a server fn runs in-process (origin
server, not a server-fn request), saveresponseState.status/statusTextbefore the call and restore them after. Headers and cookies still merge into the document as they do now. -
Or give the fn's handler and function middleware a public way to know whether it runs as an RPC. Today an app can only check internals (
x-tsr-serverFnheader plusTSS_SERVER_FN_BASE), or passhandlerTypefrom a request middleware through context:const handlerTypeMiddleware = createMiddleware().server(({ next, handlerType }) => next({ context: { isServerFnRpc: handlerType === 'serverFn' } }), ) export const startInstance = createStart(() => ({ requestMiddleware: [handlerTypeMiddleware] })) // in the fn: if (context.isServerFnRpc) setResponseStatus(503)I checked this workaround against the reproducer: documents answer 200 and the RPCs still answer 503.
Related, not duplicates:
- #7588: response reconciliation, the change that made helper state override the returned response.
- #6785 (open PR): keeps the status when a handler throws after
setResponseStatus. - #7647 (open): keeping a middleware-set status drops middleware-set headers.
- #7914 (open): response-context headers in non-2xx serialized server fn responses.
- #5107, #5407 (closed):
setResponseStatusignored withthrowand in global middleware.
This issue was drafted with an AI assistant and checked by me against the reproducer.
- Lenguaje dominante
- TypeScript
- Estrellas
- 15.3k
- Forks
- 1.9k
- Merge medio
- 1 d 5 h
- PR fusionados (30 d)
- 46
Preparar el entorno
Inicia el contenedor de desarrollo del proyecto en tu navegador, con tu propia cuenta de GitHub.
- Sin Dockerfile ni archivo de Docker Compose
- Tiene una plantilla de pull request
- Leer la guía de contribución
Primeros pasos
- Lee el issue completo y luego la guía de contribución del proyecto.
- Comenta en el issue que vas a ocuparte — evita que dos personas hagan lo mismo.
- Haz un fork del repositorio y trabaja en una rama.
- Abre un pull request que haga referencia al número del issue.
Más de TanStack/router
-
Dificultad 2/5 1-3 horas Aptitud para principiantes 85/100
Los mantenedores suelen responder en 1 día
-
Masked navigation drops the first character of the hash each time (__tempLocation hash missing '#')Posiblemente ocupada @hassanabrar202 la tomó hace 8 días. Abierto
Dificultad 2/5 1-3 horas Aptitud para principiantes 72/100
Los mantenedores suelen responder en 1 día
-
router-generator: lazy-load Prettier (costs ~300–450ms per build even when formatting is off)Posiblemente ocupada @Sheraff la tomó hace 27 días. Abiertopackage: router-generator performance
Dificultad 2/5 1-3 horas Aptitud para principiantes 85/100
Los mantenedores suelen responder en 1 día
-
router-generator: sibling `physical()` subtrees in a virtual route config generate duplicate identifiersPosiblemente ocupada @Sheraff la tomó hace 27 días. Abierto
Dificultad 2/5 1-3 horas Aptitud para principiantes 76/100
Los mantenedores suelen responder en 1 día
-
docs(router): clarify static title fallback in SPA modePosiblemente ocupada @Rohan-Dedhia la tomó hace 17 días. Abierto
Dificultad 1/5 1-3 horas Aptitud para principiantes 62/100
Los mantenedores suelen responder en 1 día
Todos los issues de TanStack/router
Issues similares
-
[BUG]: Shared links drop the configured basePath on GitHub PagesPosiblemente ocupada @anshulchikhale30-p la tomó hoy. Abiertobug
Dificultad 1/5 Menos de una hora Aptitud para principiantes 88/100
StabilityNexus/IdentityTokens-EVM-Frontend#182 · 1 comentario ·
Los mantenedores suelen responder en 1 día
-
Add: GTrekkerAbiertocheck:passed streams:add
Dificultad 1/5 Menos de una hora Aptitud para principiantes 72/100
Los mantenedores suelen responder en 1 día
-
Dificultad 2/5 1-3 horas Aptitud para principiantes 70/100
Koenkk/zigbee-herdsman-converters#13900 ·
Los mantenedores suelen responder en 1 día
-
area: ui Bug Payload OSS
Dificultad 1/5 Menos de una hora Aptitud para principiantes 88/100
payloadcms/payload#19839 ·
Los mantenedores suelen responder en 1 día
-
Dificultad 1/5 Menos de una hora Aptitud para principiantes 88/100
jeanibarz/knowledge-base-mcp-server#1291 ·
Los mantenedores suelen responder en 1 día