Skip to content

Commit cb63866

Browse files
docs: remove usage of setResponse... utilities for server routes
these utilities are not to be used when returning a `Response` which is the case in server routes closes #5377
1 parent bbf1008 commit cb63866

File tree

2 files changed

+5
-102
lines changed

2 files changed

+5
-102
lines changed

docs/start/framework/react/server-routes.md

Lines changed: 2 additions & 51 deletions
Original file line numberDiff line numberDiff line change
@@ -392,9 +392,7 @@ export const Route = createFileRoute('/hello')({
392392

393393
## Responding with a status code
394394

395-
You can set the status code of the response by either:
396-
397-
- Passing it as a property of the second argument to the `Response` constructor
395+
You can set the status code of the response by passing it as a property of the second argument to the `Response` constructor
398396

399397
```ts
400398
// routes/hello.ts
@@ -418,37 +416,11 @@ You can set the status code of the response by either:
418416
})
419417
```
420418

421-
- Using the `setResponseStatus` helper function from `@tanstack/react-start/server`
422-
423-
```ts
424-
// routes/hello.ts
425-
import { createFileRoute } from '@tanstack/react-router'
426-
import { json } from '@tanstack/react-start'
427-
import { setResponseStatus } from '@tanstack/react-start/server'
428-
429-
export const Route = createFileRoute('/hello')({
430-
server: {
431-
handlers: {
432-
GET: async ({ request, params }) => {
433-
const user = await findUser(params.id)
434-
if (!user) {
435-
setResponseStatus(404)
436-
return new Response('User not found')
437-
}
438-
return json(user)
439-
},
440-
},
441-
},
442-
})
443-
```
444-
445419
In this example, we're returning a `404` status code if the user is not found. You can set any valid HTTP status code using this method.
446420

447421
## Setting headers in the response
448422

449-
Sometimes you may need to set headers in the response. You can do this by either:
450-
451-
- Passing an object as the second argument to the `Response` constructor.
423+
Sometimes you may need to set headers in the response. You can do this by passing an object as the second argument to the `Response` constructor.
452424

453425
```ts
454426
// routes/hello.ts
@@ -469,24 +441,3 @@ Sometimes you may need to set headers in the response. You can do this by either
469441
// Visit /hello to see the response
470442
// Hello, World!
471443
```
472-
473-
- Or using the `setResponseHeaders` helper function from `@tanstack/react-start/server`.
474-
475-
```ts
476-
// routes/hello.ts
477-
import { createFileRoute } from '@tanstack/react-router'
478-
import { setResponseHeaders } from '@tanstack/react-start/server'
479-
480-
export const Route = createFileRoute('/hello')({
481-
server: {
482-
handlers: {
483-
GET: async ({ request }) => {
484-
setResponseHeaders({
485-
'Content-Type': 'text/plain',
486-
})
487-
return new Response('Hello, World!')
488-
},
489-
},
490-
},
491-
})
492-
```

docs/start/framework/solid/server-routes.md

Lines changed: 3 additions & 51 deletions
Original file line numberDiff line numberDiff line change
@@ -392,9 +392,7 @@ export const Route = createFileRoute('/hello')({
392392

393393
## Responding with a status code
394394

395-
You can set the status code of the response by either:
396-
397-
- Passing it as a property of the second argument to the `Response` constructor
395+
You can set the status code of the response by passing it as a property of the second argument to the `Response` constructor
398396

399397
```ts
400398
// routes/hello.ts
@@ -418,37 +416,11 @@ You can set the status code of the response by either:
418416
})
419417
```
420418

421-
- Using the `setResponseStatus` helper function from `@tanstack/solid-start/server`
422-
423-
```ts
424-
// routes/hello.ts
425-
import { createFileRoute } from '@tanstack/solid-router'
426-
import { json } from '@tanstack/solid-start'
427-
import { setResponseStatus } from '@tanstack/solid-start/server'
428-
429-
export const Route = createFileRoute('/hello')({
430-
server: {
431-
handlers: {
432-
GET: async ({ request, params }) => {
433-
const user = await findUser(params.id)
434-
if (!user) {
435-
setResponseStatus(404)
436-
return new Response('User not found')
437-
}
438-
return json(user)
439-
},
440-
},
441-
},
442-
})
443-
```
444-
445419
In this example, we're returning a `404` status code if the user is not found. You can set any valid HTTP status code using this method.
446420

447421
## Setting headers in the response
448422

449-
Sometimes you may need to set headers in the response. You can do this by either:
450-
451-
- Passing an object as the second argument to the `Response` constructor.
423+
Sometimes you may need to set headers in the response. You can do this by passing an object as the second argument to the `Response` constructor.
452424

453425
```ts
454426
// routes/hello.ts
@@ -464,28 +436,8 @@ Sometimes you may need to set headers in the response. You can do this by either
464436
})
465437
},
466438
},
439+
},
467440
})
468441
// Visit /hello to see the response
469442
// Hello, World!
470443
```
471-
472-
- Or using the `setResponseHeaders` helper function from `@tanstack/solid-start/server`.
473-
474-
```ts
475-
// routes/hello.ts
476-
import { createFileRoute } from '@tanstack/solid-router'
477-
import { setResponseHeaders } from '@tanstack/solid-start/server'
478-
479-
export const Route = createFileRoute('/hello')({
480-
server: {
481-
handlers: {
482-
GET: async ({ request }) => {
483-
setResponseHeaders({
484-
'Content-Type': 'text/plain',
485-
})
486-
return new Response('Hello, World!')
487-
},
488-
},
489-
},
490-
})
491-
```

0 commit comments

Comments
 (0)