From 6e4df31be309c7fea1caf4cebbcee591d3487477 Mon Sep 17 00:00:00 2001 From: Logan McAnsh Date: Mon, 23 Jan 2023 11:10:02 -0500 Subject: [PATCH] chore: update cloudflare/deno default entry.server Signed-off-by: Logan McAnsh --- .../defaults/entry.server.cloudflare.tsx | 22 ++++++++++--------- .../config/defaults/entry.server.deno.tsx | 22 ++++++++++--------- 2 files changed, 24 insertions(+), 20 deletions(-) diff --git a/packages/remix-dev/config/defaults/entry.server.cloudflare.tsx b/packages/remix-dev/config/defaults/entry.server.cloudflare.tsx index 8c102fb4019..ad7efa83372 100644 --- a/packages/remix-dev/config/defaults/entry.server.cloudflare.tsx +++ b/packages/remix-dev/config/defaults/entry.server.cloudflare.tsx @@ -1,5 +1,6 @@ -import type { EntryContext } from "@remix-run/cloudflare"; +import { type EntryContext } from "@remix-run/cloudflare"; import { RemixServer } from "@remix-run/react"; +import isbot from "isbot"; import { renderToReadableStream } from "react-dom/server"; export default async function handleRequest( @@ -8,23 +9,24 @@ export default async function handleRequest( responseHeaders: Headers, remixContext: EntryContext ) { - let didError = false; - - const stream = await renderToReadableStream( + const body = await renderToReadableStream( , { - signal: request.signal, - onError(error: unknown) { - didError = true; + onError(error) { + console.error("renderToReadableStream error"); console.error(error); + responseStatusCode = 500; }, } ); - responseHeaders.set("Content-Type", "text/html"); + if (isbot(request.headers.get("user-agent"))) { + await body.allReady; + } - return new Response(stream, { + responseHeaders.set("Content-Type", "text/html"); + return new Response(body, { headers: responseHeaders, - status: didError ? 500 : responseStatusCode, + status: responseStatusCode, }); } diff --git a/packages/remix-dev/config/defaults/entry.server.deno.tsx b/packages/remix-dev/config/defaults/entry.server.deno.tsx index bc7a87cb7b8..ad7efa83372 100644 --- a/packages/remix-dev/config/defaults/entry.server.deno.tsx +++ b/packages/remix-dev/config/defaults/entry.server.deno.tsx @@ -1,5 +1,6 @@ -import type { EntryContext } from "@remix-run/deno"; +import { type EntryContext } from "@remix-run/cloudflare"; import { RemixServer } from "@remix-run/react"; +import isbot from "isbot"; import { renderToReadableStream } from "react-dom/server"; export default async function handleRequest( @@ -8,23 +9,24 @@ export default async function handleRequest( responseHeaders: Headers, remixContext: EntryContext ) { - let didError = false; - - const stream = await renderToReadableStream( + const body = await renderToReadableStream( , { - signal: request.signal, - onError(error: unknown) { - didError = true; + onError(error) { + console.error("renderToReadableStream error"); console.error(error); + responseStatusCode = 500; }, } ); - responseHeaders.set("Content-Type", "text/html"); + if (isbot(request.headers.get("user-agent"))) { + await body.allReady; + } - return new Response(stream, { + responseHeaders.set("Content-Type", "text/html"); + return new Response(body, { headers: responseHeaders, - status: didError ? 500 : responseStatusCode, + status: responseStatusCode, }); }