From 4452dfbdad6ac17422d2a014c99e1b645cd9ce9a Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Micha=C3=ABl=20De=20Boey?= Date: Tue, 6 Dec 2022 19:56:31 +0100 Subject: [PATCH] fix(turborepo-vercel): remove streaming (#99) --- .../apps/remix-app/app/entry.server.tsx | 111 ++---------------- 1 file changed, 11 insertions(+), 100 deletions(-) diff --git a/turborepo-vercel/apps/remix-app/app/entry.server.tsx b/turborepo-vercel/apps/remix-app/app/entry.server.tsx index dc6248a20..fb8ea8709 100644 --- a/turborepo-vercel/apps/remix-app/app/entry.server.tsx +++ b/turborepo-vercel/apps/remix-app/app/entry.server.tsx @@ -1,110 +1,21 @@ -import { PassThrough } from "stream"; - import type { EntryContext } from "@remix-run/node"; -import { Response } from "@remix-run/node"; import { RemixServer } from "@remix-run/react"; -import isbot from "isbot"; -import { renderToPipeableStream } from "react-dom/server"; - -const ABORT_DELAY = 5000; - -const handleRequest = ( - request: Request, - responseStatusCode: number, - responseHeaders: Headers, - remixContext: EntryContext -) => - isbot(request.headers.get("user-agent")) - ? handleBotRequest( - request, - responseStatusCode, - responseHeaders, - remixContext - ) - : handleBrowserRequest( - request, - responseStatusCode, - responseHeaders, - remixContext - ); -export default handleRequest; +import { renderToString } from "react-dom/server"; -const handleBotRequest = ( +export default function handleRequest( request: Request, responseStatusCode: number, responseHeaders: Headers, remixContext: EntryContext -) => - new Promise((resolve, reject) => { - let didError = false; - - const { pipe, abort } = renderToPipeableStream( - , - { - onAllReady: () => { - const body = new PassThrough(); - - responseHeaders.set("Content-Type", "text/html"); - - resolve( - new Response(body, { - headers: responseHeaders, - status: didError ? 500 : responseStatusCode, - }) - ); - - pipe(body); - }, - onShellError: (error: unknown) => { - reject(error); - }, - onError: (error: unknown) => { - didError = true; - - console.error(error); - }, - } - ); - - setTimeout(abort, ABORT_DELAY); - }); - -const handleBrowserRequest = ( - request: Request, - responseStatusCode: number, - responseHeaders: Headers, - remixContext: EntryContext -) => - new Promise((resolve, reject) => { - let didError = false; - - const { pipe, abort } = renderToPipeableStream( - , - { - onShellReady: () => { - const body = new PassThrough(); - - responseHeaders.set("Content-Type", "text/html"); - - resolve( - new Response(body, { - headers: responseHeaders, - status: didError ? 500 : responseStatusCode, - }) - ); - - pipe(body); - }, - onShellError: (error: unknown) => { - reject(error); - }, - onError: (error: unknown) => { - didError = true; +) { + const markup = renderToString( + + ); - console.error(error); - }, - } - ); + responseHeaders.set("Content-Type", "text/html"); - setTimeout(abort, ABORT_DELAY); + return new Response("" + markup, { + headers: responseHeaders, + status: responseStatusCode, }); +}