diff options
author | Vitaly Takmazov | 2022-10-29 20:52:48 +0300 |
---|---|---|
committer | Vitaly Takmazov | 2023-01-13 10:37:58 +0300 |
commit | 1d6708b0f034d3e9fbddc20247a281856350fc6c (patch) | |
tree | d5e106f59a15d781bcd00d72ebf2c7e18dccefa8 /vnext/server/middleware/renderer.js | |
parent | 4853133a62c8fd9406de320e33bd1fcd1678a7c2 (diff) |
Disable Suspense/lazy import to fix SSR
Diffstat (limited to 'vnext/server/middleware/renderer.js')
-rw-r--r-- | vnext/server/middleware/renderer.js | 13 |
1 files changed, 8 insertions, 5 deletions
diff --git a/vnext/server/middleware/renderer.js b/vnext/server/middleware/renderer.js index 8edb5f57..11272f8b 100644 --- a/vnext/server/middleware/renderer.js +++ b/vnext/server/middleware/renderer.js @@ -1,11 +1,11 @@ -import ReactDOMServer from 'react-dom/server'; +import * as ReactDOMServer from 'react-dom/server'; import cookie from 'cookie'; // import our main App component import App from '../../src/App'; import { getLinks } from '../sape'; -import { StaticRouter } from 'react-router-dom'; +import { StaticRouter } from 'react-router-dom/server'; const path = require('path'); const fs = require('fs'); @@ -19,7 +19,6 @@ const serverRenderer = async (req, res, next) => { const cookies = cookie.parse(req.headers.cookie || ''); const links = await getLinks(req.originalUrl, cookies['sape_cookie']); - console.log(`URL: ${req.originalUrl} LINKS: ${links.join(' ')}`); fs.readFile(filePath, 'utf8', (err, htmlData) => { if (err) { console.error('err', err); @@ -28,10 +27,14 @@ const serverRenderer = async (req, res, next) => { const routerContext = {}; + const props = { + footer: links.join(' ') + }; + // render the app as a string const html = ReactDOMServer.renderToString( <StaticRouter location={req.baseUrl} context={routerContext}> - <App footer={links.join(' ')}/> + <App {...props} /> </StaticRouter> ); @@ -39,7 +42,7 @@ const serverRenderer = async (req, res, next) => { return res.send( htmlData.replace( '<div id="app"></div>', - `<div id="app">${html}</div>` + `<script>window.__PROPS__="${Buffer.from(JSON.stringify(props)).toString('base64')}";</script><div id="app">${html}</div>` ) ); }); |