-
Notifications
You must be signed in to change notification settings - Fork 534
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Added code splitting (lazy and Suspense), server-side rendering with …
…pipeable streams serving the non-interactive part of the code first and express added to the project to serve the stream
- Loading branch information
Showing
31 changed files
with
8,380 additions
and
82 deletions.
There are no files selected for viewing
Large diffs are not rendered by default.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,49 @@ | ||
import express from "express"; | ||
import fs from "fs"; | ||
import path from "path"; | ||
import { fileURLToPath } from "url"; | ||
import renderApp from "./dist/server/ServerApp.js"; | ||
|
||
const __dirname = path.dirname(fileURLToPath(import.meta.url)); | ||
|
||
const PORT = process.env.PORT || 3001; | ||
|
||
const html = fs | ||
.readFileSync(path.resolve(__dirname, "./dist/client/index.html")) | ||
.toString(); | ||
|
||
const parts = html.split("not rendered"); | ||
|
||
const app = express(); | ||
app.use( | ||
"/assets", | ||
express.static(path.resolve(__dirname, "./dist/client/assets")) | ||
); | ||
|
||
app.use((req, res) => { | ||
res.write(parts[0]); | ||
|
||
const stream = renderApp(req.url, { | ||
onShellReady() { | ||
// if it is crawler, do nothing here | ||
stream.pipe(res); | ||
}, | ||
onShellError() { | ||
// do error handling | ||
}, | ||
onAllReady() { | ||
// if it is crawler, | ||
// stream.pipe(res) | ||
|
||
// last thing to write | ||
res.write(parts[1]); | ||
res.end(); | ||
}, | ||
onError(err) { | ||
console.error(err); | ||
}, | ||
}); | ||
}); | ||
|
||
console.log(`listening on http://localhost:${PORT}`); | ||
app.listen(PORT); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,10 @@ | ||
import { hydrateRoot } from "react-dom/client"; | ||
import { BrowserRouter } from "react-router-dom"; | ||
import App from "./App"; | ||
|
||
hydrateRoot( | ||
document.getElementById("root"), | ||
<BrowserRouter> | ||
<App /> | ||
</BrowserRouter> | ||
); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,14 @@ | ||
import { renderToPipeableStream } from "react-dom/server"; | ||
import { StaticRouter } from "react-router-dom/server"; | ||
import App from "./App"; | ||
|
||
export default function render(url, opts) { | ||
const stream = renderToPipeableStream( | ||
<StaticRouter location={url}> | ||
<App /> | ||
</StaticRouter>, | ||
opts | ||
); | ||
|
||
return stream; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,37 @@ | ||
{ | ||
"extends": [ | ||
"eslint:recommended", | ||
"plugin:import/errors", | ||
"plugin:react/recommended", | ||
"plugin:jsx-a11y/recommended", | ||
"plugin:react-hooks/recommended", | ||
"prettier" | ||
], | ||
"rules": { | ||
"react/prop-types": 0, | ||
"react/react-in-jsx-scope": 0 | ||
}, | ||
"plugins": ["react", "import", "jsx-a11y"], | ||
"parserOptions": { | ||
"ecmaVersion": 2022, | ||
"sourceType": "module", | ||
"ecmaFeatures": { | ||
"jsx": true | ||
} | ||
}, | ||
"env": { | ||
"es6": true, | ||
"browser": true, | ||
"node": true | ||
}, | ||
"settings": { | ||
"react": { | ||
"version": "detect" | ||
}, | ||
"import/resolver": { | ||
"node": { | ||
"extensions": [".js", ".jsx"] | ||
} | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,7 @@ | ||
node_modules | ||
.parcel-cache/ | ||
dist/ | ||
.env | ||
.DS_Store | ||
coverage/ | ||
.vscode/ |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
{} |
Oops, something went wrong.