Skip to content

Very basic SSR support #184

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Draft
wants to merge 1 commit into
base: master
Choose a base branch
from
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 6 additions & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -32,10 +32,14 @@
"start": "react-scripts start",
"lint": "eslint '*/**/*.{js,ts,tsx}' --max-warnings=0",
"build": "PUBLIC_URL=./ react-scripts build",
"postbuild": "react-snap",
"test": "react-scripts test",
"test:jenkins": "react-scripts test --ci ---coverage --reporters=default --reporters=jest-junit",
"eject": "react-scripts eject"
},
"reactSnap": {
"asyncScriptTags": true
},
"eslintConfig": {
"extends": "react-app"
},
Expand All @@ -60,7 +64,8 @@
"eslint-plugin-react-app": "^6.2.2",
"eslint-plugin-react-hooks": "^4.1.0",
"jest-junit": "^12.0.0",
"prettier": "^2.1.1"
"prettier": "^2.1.1",
"react-snap": "^1.23.0"
},
"resolutions": {
"**/react": "17.0.2",
Expand Down
24 changes: 17 additions & 7 deletions src/index.tsx
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import React from "react";
import { render } from "react-dom";
import { render, hydrate } from "react-dom";
import { Provider } from "react-redux";
import { applyMiddleware, combineReducers, createStore } from "redux";
import thunkMiddleware from "redux-thunk";
Expand All @@ -20,12 +20,22 @@ if (searchParams.has("version")) {
version = searchParams.get("version") || version;
}

render(
<Provider store={store}>
<App versionFromParams={version} />
</Provider>,
document.getElementById("root")
);
const rootElement = document.getElementById("root");
if (rootElement && rootElement.hasChildNodes()) {
hydrate(
<Provider store={store}>
<App versionFromParams={version} />
</Provider>,
rootElement
);
} else {
render(
<Provider store={store}>
<App versionFromParams={version} />
</Provider>,
rootElement
);
}

// If you want your app to work offline and load faster, you can change
// unregister() to register() below. Note this comes with some pitfalls.
Expand Down
Loading