Skip to content

Commit

Permalink
fix - axios problem on ssr, check axios/axios#2968 before update
Browse files Browse the repository at this point in the history
  • Loading branch information
Flavien Rebattet committed Mar 12, 2021
1 parent 1038270 commit 03d3aae
Show file tree
Hide file tree
Showing 4 changed files with 22 additions and 18 deletions.
2 changes: 1 addition & 1 deletion zoop-f-mf-app4-ssr/package.json
Expand Up @@ -19,7 +19,7 @@
"@com.zooplus/zoop-f-theme": "file:../zoop-f-theme",
"@types/react-redux": "^7.1.16",
"@types/react-router-config": "^5.0.2",
"axios": "0.21.1",
"axios": "0.16.2",
"babel-polyfill": "^6.26.0",
"bootstrap": "^4.6.0",
"compression": "1.7.4",
Expand Down
24 changes: 10 additions & 14 deletions zoop-f-mf-app4-ssr/src/helpers/renderer.tsx
Expand Up @@ -10,17 +10,13 @@ import { printDrainHydrateMarks } from 'react-imported-component';

// Renderer generate HTML from React and load redux state and append script tag with client bundle.
export default function renderer(req, store, context) {
const App = () => {
return (
<Provider store={store}>
<StaticRouter location={req.path} context={context}>
<div>{renderRoutes(Routes)}</div>
</StaticRouter>
</Provider>
);
};

const content = renderToString(<App />);
const content = renderToString(
<Provider store={store}>
<StaticRouter location={req.path} context={context}>
<div>{renderRoutes(Routes)}</div>
</StaticRouter>
</Provider>,
);
// We pass the url via req.path

const helmet = Helmet.renderStatic(); // Returns an object with all the setup tags with Helmet in JSX.
Expand All @@ -36,9 +32,9 @@ export default function renderer(req, store, context) {
</head>
<body>
<div id="root">${content}</div>
<script>window.INITIAL_STATE = ${store.getState()}</script>
<script defer="defer" src="main.bundle.js"></script>
<script defer="defer" src="vendors.bundle.js"></script>
<script>window.INITIAL_STATE = ${JSON.stringify(store.getState()).replace(/</g, '\\u003c')}</script>
<script src="main.bundle.js"></script>
<script src="vendors.bundle.js"></script>
${printDrainHydrateMarks()}
</body>
</html>
Expand Down
2 changes: 1 addition & 1 deletion zoop-f-mf-app4-ssr/src/index.ts
Expand Up @@ -36,7 +36,6 @@ app.use(express.static('public')); // Tell express that this folder is accessibl
app.get('*', (req, res) => {
// Create Redux store before rendering the html
const store = createStore(req); // reference to server side redux store.

// Data Loading logic
// execute loadData functions for each components and returning an array of promises that we can wait to resolve.
const promises = matchRoutes(Routes, req.path)
Expand All @@ -57,6 +56,7 @@ app.get('*', (req, res) => {
Promise.all(promises).then(() => {
// Context of the route, is used to get informations from static router.
const context = {};

// Server side store is now built correctly.
// Renderer generate HTML from React and append script tag with client bundle.
const content = renderer(req, store, context);
Expand Down
12 changes: 10 additions & 2 deletions zoop-f-mf-app4-ssr/yarn.lock
Expand Up @@ -2375,7 +2375,15 @@ aws4@^1.8.0:
resolved "https://registry.yarnpkg.com/aws4/-/aws4-1.11.0.tgz#d61f46d83b2519250e2784daf5b09479a8b41c59"
integrity sha512-xh1Rl34h6Fi1DC2WWKfxUTVqRsNnr6LsKz2+hfwDxQJWmrx8+c7ylaqBMcHfl1U1r2dsifOvKX3LQuLNZ+XSvA==

axios@0.21.1, axios@^0.21.1:
axios@0.16.2:
version "0.16.2"
resolved "https://registry.yarnpkg.com/axios/-/axios-0.16.2.tgz#ba4f92f17167dfbab40983785454b9ac149c3c6d"
integrity sha1-uk+S8XFn37q0CYN4VFS5rBScPG0=
dependencies:
follow-redirects "^1.2.3"
is-buffer "^1.1.5"

axios@^0.21.1:
version "0.21.1"
resolved "https://registry.yarnpkg.com/axios/-/axios-0.21.1.tgz#22563481962f4d6bde9a76d516ef0e5d3c09b2b8"
integrity sha512-dKQiRHxGD9PPRIUNIWvZhPTPpl1rf/OxTYKsqKUDjBwYylTvV7SjSHJb9ratfyzM6wCdLCOYLzs73qpg5c4iGA==
Expand Down Expand Up @@ -4969,7 +4977,7 @@ flatten@^1.0.2:
resolved "https://registry.yarnpkg.com/flatten/-/flatten-1.0.3.tgz#c1283ac9f27b368abc1e36d1ff7b04501a30356b"
integrity sha512-dVsPA/UwQ8+2uoFe5GHtiBMu48dWLTdsuEd7CKGlZlD78r1TTWBvDuFaFGKCo/ZfEr95Uk56vZoX86OsHkUeIg==

follow-redirects@^1.0.0, follow-redirects@^1.10.0:
follow-redirects@^1.0.0, follow-redirects@^1.10.0, follow-redirects@^1.2.3:
version "1.13.3"
resolved "https://registry.yarnpkg.com/follow-redirects/-/follow-redirects-1.13.3.tgz#e5598ad50174c1bc4e872301e82ac2cd97f90267"
integrity sha512-DUgl6+HDzB0iEptNQEXLx/KhTmDb8tZUHSeLqpnjpknR70H0nC2t9N73BK6fN4hOvJ84pKlIQVQ4k5FFlBedKA==
Expand Down

0 comments on commit 03d3aae

Please sign in to comment.