Skip to the content

Capsid menu

app/entry.server.tsx

31 lines and 2 functions in DrDustinEdwards/carrel, at commit d5d5e82 on 2026-10-24. This file on GitHub.

Functions

The functions of entry.server.tsx
FunctionLinesComplexityCoveredCRAPMutation
handleRequest8 to 3530%WatchCRAP 12No data: mutation testing has not run on this repo yet
onError23 to 2620%WatchCRAP 6No data: mutation testing has not run on this repo yet

Imports

It imports app/lib/context.ts. No module of this repo imports it.

Source

import { isbot } from "isbot";
import { renderToReadableStream } from "react-dom/server";
import type { EntryContext, RouterContextProvider } from "react-router";
import { ServerRouter } from "react-router";

import { getNonce } from "~/lib/context";

export default async function handleRequest(
  request: Request,
  responseStatusCode: number,
  responseHeaders: Headers,
  routerContext: EntryContext,
  loadContext: RouterContextProvider,
) {
  // The ServerRouter prop nonces React Router's streaming scripts; react-dom's own inline scripts
  // take it only from the render option. Without both, the policy blocks hydration.
  const nonce = getNonce(loadContext);
  let shellRendered = false;
  const body = await renderToReadableStream(
    <ServerRouter context={routerContext} url={request.url} nonce={nonce} />,
    {
      nonce,
      onError(error: unknown) {
        responseStatusCode = 500;
        if (shellRendered) console.error(error);
      },
    },
  );
  shellRendered = true;

  if (isbot(request.headers.get("user-agent") || "")) await body.allReady;

  responseHeaders.set("Content-Type", "text/html; charset=utf-8");
  return new Response(body, { headers: responseHeaders, status: responseStatusCode });
}