11import { PassThrough } from "node:stream"
2- import type { AppLoadContext , EntryContext } from "@remix-run/node"
3- import { RemixServer } from "@remix-run/react"
2+ import { createReadableStreamFromReadable } from "@react-router/node"
43import type { Context } from "hono"
54import { createInstance } from "i18next"
65import { isbot } from "isbot"
76import { renderToPipeableStream } from "react-dom/server"
87import { I18nextProvider , initReactI18next } from "react-i18next"
8+ import { type AppLoadContext , type EntryContext , ServerRouter } from "react-router"
99import { createHonoServer } from "react-router-hono-server/node"
1010import { i18next } from "remix-hono/i18next"
1111import { getClientEnv , initEnv } from "./env.server"
1212import i18n from "./localization/i18n" // your i18n configuration file
1313import i18nextOpts from "./localization/i18n.server"
1414import { resources } from "./localization/resource"
15-
1615const ABORT_DELAY = 5000
1716
1817export default async function handleRequest (
1918 request : Request ,
2019 responseStatusCode : number ,
2120 responseHeaders : Headers ,
22- remixContext : EntryContext ,
21+ context : EntryContext ,
2322 appContext : AppLoadContext
2423) {
2524 const callbackName = isbot ( request . headers . get ( "user-agent" ) ) ? "onAllReady" : "onShellReady"
2625 const instance = createInstance ( )
2726 const lng = appContext . lang
28- const ns = i18nextOpts . getRouteNamespaces ( remixContext )
27+ // biome-ignore lint/suspicious/noExplicitAny: <explanation>
28+ const ns = i18nextOpts . getRouteNamespaces ( context as any )
2929
3030 await instance
3131 . use ( initReactI18next ) // Tell our instance to use react-i18next
@@ -41,17 +41,17 @@ export default async function handleRequest(
4141
4242 const { pipe, abort } = renderToPipeableStream (
4343 < I18nextProvider i18n = { instance } >
44- < RemixServer context = { remixContext } url = { request . url } />
44+ < ServerRouter abortDelay = { ABORT_DELAY } context = { context } url = { request . url } />
4545 </ I18nextProvider > ,
4646 {
4747 [ callbackName ] : ( ) => {
4848 const body = new PassThrough ( )
49-
49+ const stream = createReadableStreamFromReadable ( body )
5050 responseHeaders . set ( "Content-Type" , "text/html" )
5151
5252 resolve (
5353 // @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
54- appContext . body ( body , {
54+ appContext . body ( stream , {
5555 headers : responseHeaders ,
5656 status : didError ? 500 : responseStatusCode ,
5757 } )
@@ -64,7 +64,7 @@ export default async function handleRequest(
6464 } ,
6565 onError ( error : unknown ) {
6666 didError = true
67-
67+ // biome-ignore lint/suspicious/noConsole: We console log the error
6868 console . error ( error )
6969 } ,
7070 }
@@ -100,7 +100,7 @@ interface LoadContext extends Awaited<ReturnType<typeof getLoadContext>> {}
100100/**
101101 * Declare our loaders and actions context type
102102 */
103- declare module "@remix-run/node " {
103+ declare module "react-router " {
104104 interface AppLoadContext extends Omit < LoadContext , "body" > { }
105105}
106106
0 commit comments