From 5cee3c280c1ba9b93e243e0bccc9c3ff2106623b Mon Sep 17 00:00:00 2001 From: Sebastian Markbage Date: Sat, 17 Feb 2024 23:32:23 -0500 Subject: [PATCH] Recover from SSR error in Flight fixture --- fixtures/flight/server/global.js | 13 ++++++++++++- fixtures/flight/server/region.js | 9 ++------- 2 files changed, 14 insertions(+), 8 deletions(-) diff --git a/fixtures/flight/server/global.js b/fixtures/flight/server/global.js index 6e284e78d55ee..779270e16f44e 100644 --- a/fixtures/flight/server/global.js +++ b/fixtures/flight/server/global.js @@ -174,8 +174,19 @@ app.all('/', async function (req, res, next) { const {pipe} = renderToPipeableStream(React.createElement(Root), { bootstrapScripts: mainJSChunks, formState: formState, + onShellReady() { + pipe(res); + }, + onShellError(error) { + const {pipe: pipeError} = renderToPipeableStream( + React.createElement('html', null, React.createElement('body')), + { + bootstrapScripts: mainJSChunks, + } + ); + pipeError(res); + }, }); - pipe(res); } catch (e) { console.error(`Failed to SSR: ${e.stack}`); res.statusCode = 500; diff --git a/fixtures/flight/server/region.js b/fixtures/flight/server/region.js index e89f113b7cad6..3a12d4e118cd8 100644 --- a/fixtures/flight/server/region.js +++ b/fixtures/flight/server/region.js @@ -103,13 +103,8 @@ app.get('/', async function (req, res) { }); app.post('/', bodyParser.text(), async function (req, res) { - const { - renderToPipeableStream, - decodeReply, - decodeReplyFromBusboy, - decodeAction, - decodeFormState, - } = await import('react-server-dom-webpack/server'); + const {decodeReply, decodeReplyFromBusboy, decodeAction, decodeFormState} = + await import('react-server-dom-webpack/server'); const serverReference = req.get('rsc-action'); if (serverReference) { // This is the client-side case