From d352fd09315276b3def318d91f462ee7c49fb1af Mon Sep 17 00:00:00 2001 From: Kay Date: Fri, 1 Apr 2022 01:26:12 +0200 Subject: [PATCH] Fix for SSR2 fixture not working locally (#24237) * SS2 fixture not working locally fix * Fix prettier issue * prettier excess line fix * Update render.js * Update README.md Co-authored-by: dan --- fixtures/ssr2/README.md | 30 ++++++++++++++++++++++++++++++ fixtures/ssr2/scripts/build.js | 1 - fixtures/ssr2/server/render.js | 8 ++++++-- 3 files changed, 36 insertions(+), 3 deletions(-) create mode 100644 fixtures/ssr2/README.md diff --git a/fixtures/ssr2/README.md b/fixtures/ssr2/README.md new file mode 100644 index 0000000000..e41d47149e --- /dev/null +++ b/fixtures/ssr2/README.md @@ -0,0 +1,30 @@ +# SSR Fixtures + +A set of test cases for quickly identifying issues with server-side rendering. + +## Setup + +To reference a local build of React, first run `npm run build` at the root +of the React project. Then: + +``` +cd fixtures/ssr2 +yarn +yarn start +``` + +The `start` command runs a webpack dev server and a server-side rendering server in development mode with hot reloading. + +**Note: whenever you make changes to React and rebuild it, you need to re-run `yarn` in this folder:** + +``` +yarn +``` + +If you want to try the production mode instead run: + +``` +yarn start:prod +``` + +This will pre-build all static resources and then start a server-side rendering HTTP server that hosts the React app and service the static resources (without hot reloading). diff --git a/fixtures/ssr2/scripts/build.js b/fixtures/ssr2/scripts/build.js index 24606053d9..452f7c750f 100644 --- a/fixtures/ssr2/scripts/build.js +++ b/fixtures/ssr2/scripts/build.js @@ -40,7 +40,6 @@ webpack( console.error(err.details); } process.exit(1); - return; } const info = stats.toJson(); if (stats.hasErrors()) { diff --git a/fixtures/ssr2/server/render.js b/fixtures/ssr2/server/render.js index ea2b6e4696..9c70f8ba01 100644 --- a/fixtures/ssr2/server/render.js +++ b/fixtures/ssr2/server/render.js @@ -20,6 +20,7 @@ let assets = { }; module.exports = function render(url, res) { + const data = createServerData(); // This is how you would wire it up previously: // // res.send( @@ -36,14 +37,17 @@ module.exports = function render(url, res) { console.error('Fatal', error); }); let didError = false; - const data = createServerData(); const {pipe, abort} = renderToPipeableStream( , { bootstrapScripts: [assets['main.js']], - onCompleteShell() { + onAllReady() { + // Full completion. + // You can use this for SSG or crawlers. + }, + onShellReady() { // If something errored before we started streaming, we set the error code appropriately. res.statusCode = didError ? 500 : 200; res.setHeader('Content-type', 'text/html');