-
Notifications
You must be signed in to change notification settings - Fork 31
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
SSR functionality #258
base: ssr
Are you sure you want to change the base?
SSR functionality #258
Conversation
} | ||
|
||
handleResponseCallback(response) { | ||
if(response.status === 401) { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
switch(response.status) {
case 401:
case 204:
case 500:
...
}
redirect: routerContext.url, | ||
// TODO templating | ||
content: contents | ||
.split('<div id="root"></div>').join(`<div id="root">${html}</div>`) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
.split('<div id="root"></div>').join(
<div id="root" data-initial-state="${state}">${html}</div>
) ?`
.split('</head>').join(`${helmet.title.toString()}${helmet.meta.toString()}${helmet.link.toString()}<style>${css}</style></head>`) | ||
.split('<html ').join(`<html ${helmet.htmlAttributes.toString()} `) | ||
.split('<body ').join(`<body ${helmet.bodyAttributes.toString()} `) | ||
.split('<div id="root"').join(`<div id="root" data-initial-state="${state}"`), |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
you can pass this data attribute in first iteration
# ssr bundle and server will be available in dist/ssr | ||
# to disable just remove the value, e.g `SSR=` | ||
# WARNING! This will not work for non-SPA applications. | ||
SSR=true |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Maybe we need to make SPA=true and SSR=?
return next() | ||
} | ||
|
||
let accept = String(get(req, 'headers.accept', '')) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
where do you use this variable?
|
||
let accept = String(get(req, 'headers.accept', '')) | ||
|
||
let isWebpackAsset = getFilenameFromUrl( |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
const
req.url | ||
) | ||
|
||
let isProxyMatched = proxyMatch( |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
const
let lastIndex = 0 | ||
let alreadyEmited = new Set() | ||
|
||
export default function usuSSREffect(func) { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
usu -> use
import App from './App' | ||
|
||
|
||
render( | ||
<App store={store} history={history} />, | ||
let needHydrate = Boolean(document.getElementById('root').dataset.initialState) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
const
commands
yarn start
now starts webpack-dev-server + ssr serveryarn start:web
legacy mode to run only webpack-dev-server (useful for slow machines)yarn ssr
use this to run SSR node server on the productionyarn ssr:dev
dev mode for ssr server, allow to test SSR without webpackmisc notes
yarn start:web
to disable SSR in development mode on slow computers. but this is not recommended. you need to check SSR build on pre-commit hook in this caselocalStorage.setItem('_SSR_DEBUG_', true)
(do not forgot to remove itlocalStorage.removeItem('_SSR_DEBUG_')
)code restrictions
process.env.SSR ? (mock) : window.navigator
)useSSREffect
hookTODO before merge
TODO non-critical
CI notes
yarn build
- no changesyarn ssr
- run nodejs server that build and serves static.yarn build
to CI tests (to prevent developers use browser-specific features in shared code)examples
the same thing, but using hooks:
in case if you need custom request you can use resource custom requests or use api module. you need to set data to redux store manually in last case. use own requests via fetch/xhr or other modules doesn't supported and need a lot of custom code.