Skip to content

Commit 3ef3a00

Browse files
committed
Update entry.server docs on optionality
1 parent 00225e0 commit 3ef3a00

File tree

1 file changed

+12
-10
lines changed

1 file changed

+12
-10
lines changed

docs/api/framework-conventions/entry.server.tsx.md

Lines changed: 12 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -9,17 +9,18 @@ order: 5
99

1010
## Summary
1111

12-
<docs-info>
13-
This file is optional
14-
</docs-info>
15-
1612
This file is the server-side entry point that controls how your React Router application generates HTTP responses on the server.
1713

1814
This module should render the markup for the current page using a [`<ServerRouter>`][serverrouter] element with the `context` and `url` for the current request. This markup will (optionally) be re-hydrated once JavaScript loads in the browser using the [client entry module][client-entry].
1915

16+
<docs-info>This file is optional if you are running on Node. If it is not present, a [default implementation][node-streaming-entry-server] will be used.
17+
<br/>
18+
<br/>
19+
If you are using another runtime (i.e., Cloudflare) then you need to include this file. You can find sample implementations in the [templates repository][templates-repo].</docs-info>
20+
2021
## Generating `entry.server.tsx`
2122

22-
By default, React Router will handle generating the HTTP Response for you. You can reveal the default entry server file with the following:
23+
When running in Node, React Router will handle generating the HTTP Response for you. You can reveal the default entry server file with the following:
2324

2425
```shellscript nonumber
2526
npx react-router reveal
@@ -42,7 +43,7 @@ export default function handleRequest(
4243
request: Request,
4344
responseStatusCode: number,
4445
responseHeaders: Headers,
45-
routerContext: EntryContext
46+
routerContext: EntryContext,
4647
) {
4748
return new Promise((resolve, reject) => {
4849
const { pipe, abort } = renderToPipeableStream(
@@ -62,15 +63,15 @@ export default function handleRequest(
6263
new Response(stream, {
6364
headers: responseHeaders,
6465
status: responseStatusCode,
65-
})
66+
}),
6667
);
6768

6869
pipe(body);
6970
},
7071
onShellError(error: unknown) {
7172
reject(error);
7273
},
73-
}
74+
},
7475
);
7576
});
7677
}
@@ -113,7 +114,7 @@ export function handleDataRequest(
113114
request,
114115
params,
115116
context,
116-
}: LoaderFunctionArgs | ActionFunctionArgs
117+
}: LoaderFunctionArgs | ActionFunctionArgs,
117118
) {
118119
response.headers.set("X-Custom-Header", "value");
119120
return response;
@@ -131,7 +132,7 @@ export function handleError(
131132
request,
132133
params,
133134
context,
134-
}: LoaderFunctionArgs | ActionFunctionArgs
135+
}: LoaderFunctionArgs | ActionFunctionArgs,
135136
) {
136137
if (!request.signal.aborted) {
137138
sendErrorToErrorReportingService(error);
@@ -160,3 +161,4 @@ Note that this does not handle thrown `Response` instances from your `loader`/`a
160161
[rendertopipeablestream]: https://react.dev/reference/react-dom/server/renderToPipeableStream
161162
[rendertoreadablestream]: https://react.dev/reference/react-dom/server/renderToReadableStream
162163
[node-streaming-entry-server]: https://github.com/remix-run/react-router/blob/dev/packages/react-router-dev/config/defaults/entry.server.node.tsx
164+
[templates-repo]: https://github.com/remix-run/react-router-templates

0 commit comments

Comments
 (0)