Skip to content

Commit

Permalink
Recover from SSR error in Flight fixture (facebook#28368)
Browse files Browse the repository at this point in the history
If an error happens before the shell, we need to handle it. In this case
we choose the strategy of rendering a blank document and client
rendering the app. Which will intentionally have a hydration mismatch.
  • Loading branch information
sebmarkbage authored and AndyPengc12 committed Apr 15, 2024
1 parent a104683 commit 2987609
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 8 deletions.
13 changes: 12 additions & 1 deletion fixtures/flight/server/global.js
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down
9 changes: 2 additions & 7 deletions fixtures/flight/server/region.js
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down

0 comments on commit 2987609

Please sign in to comment.