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 <dan.abramov@gmail.com>
Kay committed
Apr 1, 2022 at 01:26 UTC
d352fd09315276b3def318d91f462ee7c49fb1af
3 files changed
+36
-3
fixtures/ssr2/README.md
new
+30
@@ -0,0 +1,30 @@
1
+# SSR Fixtures
2
+
3
+A set of test cases for quickly identifying issues with server-side rendering.
4
+
5
+## Setup
6
+
7
+To reference a local build of React, first run `npm run build` at the root
8
+of the React project. Then:
9
+
10
+```
11
+cd fixtures/ssr2
12
+yarn
13
+yarn start
14
+```
15
+
16
+The `start` command runs a webpack dev server and a server-side rendering server in development mode with hot reloading.
17
+
18
+**Note: whenever you make changes to React and rebuild it, you need to re-run `yarn` in this folder:**
19
+
20
+```
21
+yarn
22
+```
23
+
24
+If you want to try the production mode instead run:
25
+
26
+```
27
+yarn start:prod
28
+```
29
+
30
+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).
fixtures/ssr2/scripts/build.js
-1
@@ -40,7 +40,6 @@ webpack(
40
console.error(err.details);
41
}
42
process.exit(1);
43
- return;
43
}
44
const info = stats.toJson();
45
if (stats.hasErrors()) {
fixtures/ssr2/server/render.js
+6
-2
@@ -20,6 +20,7 @@ let assets = {
20
};
21
22
module.exports = function render(url, res) {
23
+ const data = createServerData();
24
// This is how you would wire it up previously:
25
//
26
// res.send(
@@ -36,14 +37,17 @@ module.exports = function render(url, res) {
37
console.error('Fatal', error);
38
});
39
let didError = false;
39
- const data = createServerData();
40
const {pipe, abort} = renderToPipeableStream(
41
<DataProvider data={data}>
42
<App assets={assets} />
43
</DataProvider>,
44
{
45
bootstrapScripts: [assets['main.js']],
46
- onCompleteShell() {
46
+ onAllReady() {
47
+ // Full completion.
48
+ // You can use this for SSG or crawlers.
49
+ },
50
+ onShellReady() {
51
// If something errored before we started streaming, we set the error code appropriately.
52
res.statusCode = didError ? 500 : 200;
53
res.setHeader('Content-type', 'text/html');