MCPcopy Create free account
hub / github.com/code-forge-io/react-router-devtools / handleRequest

Function handleRequest

docs/app/entry.server.tsx:20–79  ·  view source on GitHub ↗
(
	request: Request,
	responseStatusCode: number,
	responseHeaders: Headers,
	context: EntryContext,
	appContext: AppLoadContext
)

Source from the content-addressed store, hash-verified

18await preloadSearchIndexes()
19
20export default async function handleRequest(
21 request: Request,
22 responseStatusCode: number,
23 responseHeaders: Headers,
24 context: EntryContext,
25 appContext: AppLoadContext
26) {
27 const callbackName = isbot(request.headers.get("user-agent")) ? "onAllReady" : "onShellReady"
28 const instance = createInstance()
29 const lng = appContext.lang
30 // biome-ignore lint/suspicious/noExplicitAny: <explanation>
31 const ns = i18nextOpts.getRouteNamespaces(context as any)
32
33 await instance
34 .use(initReactI18next) // Tell our instance to use react-i18next
35 .init({
36 ...i18n, // spread the configuration
37 lng, // The locale we detected above
38 ns, // The namespaces the routes about to render wants to use
39 resources,
40 })
41
42 return new Promise((resolve, reject) => {
43 let didError = false
44
45 const { pipe, abort } = renderToPipeableStream(
46 <I18nextProvider i18n={instance}>
47 <ServerRouter context={context} url={request.url} />
48 </I18nextProvider>,
49 {
50 [callbackName]: () => {
51 const body = new PassThrough()
52 const stream = createReadableStreamFromReadable(body)
53 responseHeaders.set("Content-Type", "text/html")
54
55 resolve(
56 // @ts-expect-error - We purposely do not define the body as existent so it's not used inside loaders as it's injected there as well
57 appContext.body(stream, {
58 headers: responseHeaders,
59 status: didError ? 500 : responseStatusCode,
60 })
61 )
62
63 pipe(body)
64 },
65 onShellError(error: unknown) {
66 reject(error)
67 },
68 onError(error: unknown) {
69 didError = true
70 // biome-ignore lint/suspicious/noConsole: We console log the error
71 console.error(error)
72 },
73 }
74 )
75 // Abort the streaming render pass after 11 seconds so to allow the rejected
76 // boundaries to be flushed
77 setTimeout(abort, streamTimeout + 1000)

Callers

nothing calls this directly

Calls

no outgoing calls

Tested by

no test coverage detected

Used in the wild real call sites across dependent graphs

searching dependent graphs…