From 41006f9e4da90fc806ec2306d3931d3beabf05ae Mon Sep 17 00:00:00 2001 From: Hiroshi Ogawa Date: Mon, 8 Apr 2024 09:42:23 +0900 Subject: [PATCH] feat(react-server): trigger error overlay on server error --- packages/react-server/src/entry/react-server.tsx | 9 +++++++++ packages/react-server/src/entry/server.tsx | 9 +++++++++ 2 files changed, 18 insertions(+) diff --git a/packages/react-server/src/entry/react-server.tsx b/packages/react-server/src/entry/react-server.tsx index 981c5e0b1..716e5d26c 100644 --- a/packages/react-server/src/entry/react-server.tsx +++ b/packages/react-server/src/entry/react-server.tsx @@ -115,6 +115,15 @@ const reactServerOnError: RenderToReadableStreamOptions["onError"] = ( }); if (!(error instanceof ReactServerDigestError)) { console.error("[react-server:renderToReadableStream]", error); + if (import.meta.env.DEV && error instanceof Error) { + __global.dev.server.hot.send({ + type: "error", + err: { + message: error.message, + stack: error.stack ?? "", + }, + }); + } } const serverError = error instanceof ReactServerDigestError diff --git a/packages/react-server/src/entry/server.tsx b/packages/react-server/src/entry/server.tsx index e12369a6f..24674b37b 100644 --- a/packages/react-server/src/entry/server.tsx +++ b/packages/react-server/src/entry/server.tsx @@ -132,6 +132,15 @@ export async function renderHtml( debug("renderToReadableStream", { error, errorInfo }); if (!getErrorContext(error)) { console.error("[react-dom:renderToReadableStream]", error); + if (import.meta.env.DEV && error instanceof Error) { + __global.dev.server.hot.send({ + type: "error", + err: { + message: error.message, + stack: error.stack ?? "", + }, + }); + } } }, });