app/entry.server.tsx
40 lines and 2 functions in DrDustinEdwards/dustinedwards-info, at commit 1590ba4 on 2026-10-24. This file on GitHub.
Functions
| Function | Lines | Complexity | Covered | CRAP | Mutation |
|---|---|---|---|---|---|
| handleRequest | 8 to 46 | 1 | No data: no coverage report in this map | No data: no coverage report in this map | No data: no mutants in this code |
| onError | 27 to 33 | 2 | No data: no coverage report in this map | No data: no coverage report in this map | No data: no mutants in this code |
Imports
It imports app/lib/context.ts, app/lib/error-message.mjs. No module of this repo imports it.
Source
import type { EntryContext, RouterContextProvider } from "react-router";
import { ServerRouter } from "react-router";
import { renderToReadableStream } from "react-dom/server";
import { getNonce } from "~/lib/context";
import { errorMessage } from "~/lib/error-message.mjs";
export default async function handleRequest(
request: Request,
responseStatusCode: number,
responseHeaders: Headers,
routerContext: EntryContext,
// The request context `workers/app.ts` built and set `nonceContext` into (admin paths only).
loadContext: RouterContextProvider,
) {
let shellRendered = false;
// The ServerRouter prop nonces React Router's streaming scripts; without it an enforcing CSP blocks
// the hydration payload. react-dom's own inline scripts take the nonce only from the render option.
// Undefined on public pages, which do not hydrate and stream no inline script of their own.
const nonce = getNonce(loadContext);
const body = await renderToReadableStream(
<ServerRouter context={routerContext} url={request.url} nonce={nonce} />,
{
nonce,
onError(error: unknown) {
responseStatusCode = 500;
// Errors before the shell renders reject and are logged in handleDocumentRequest.
if (shellRendered) {
console.error(JSON.stringify({ alert: "render-failed-after-shell", detail: errorMessage(error) }));
}
},
},
);
shellRendered = true;
// No `await body.allReady` for crawlers: the only Suspense boundary is on the admin plane. If a
// public route ever streams one, restore the wait, not a user-agent sniff.
responseHeaders.set("Content-Type", "text/html");
return new Response(body, {
headers: responseHeaders,
status: responseStatusCode,
});
}