react-rails
react-rails copied to clipboard
How to using it with react-loadable SSR preloadAll?
I want to use this lib with react-loadable with SSR. An example given in react-loadable using Express.
const app = express();
app.get('/', (req, res) => {
res.send(`
<!doctype html>
<html lang="en">
<head>...</head>
<body>
<div id="app">${ReactDOMServer.renderToString(<App/>)}</div>
<script src="/dist/main.js"></script>
</body>
</html>
`);
});
Loadable.preloadAll().then(() => {
app.listen(3000, () => {
console.log('Running on http://localhost:3000/');
});
})
where Loadable.preloadAll() preloads all the lazyloads component then serves JS file.
I can load my app normally on client side. But with prerender: true, I get the follow error.
React::ServerRendering::PrerenderError - Encountered error "#<ExecJS::ProgramError: Invariant Violation: Element type is invalid: expected a string (for built-in components) or a class/function (for composite components) but got: undefined. You likely forgot to export your component from the file it's defined in, or you might have mixed up default and named imports.>" when prerendering App with {___PROPS___}
invariant ((execjs):118729:19)
ReactDOMServerRenderer.render ((execjs):122170:11)
ReactDOMServerRenderer.read ((execjs):121879:33)
Object.renderToString ((execjs):122390:31)
Object.serverRender ((execjs):169169:42)
(execjs):6:45
(execjs):18:13
How can I go achieve it in Rails?
Hello, I'm interested with this too, been trying different things for several hours already.
I'm getting window is not define upon importing react-loadable however.
Check out loadable-components.
While React on Rails was advocating react-loadable 6 months ago, we no longer are.
react-loadable may not be maintained.
My team at ShakaCode is working on an example of this with React on Rails.
@justin808 any news? I would like to see an example of SSR with loadable-components on rails
@ops1ops if you Sign up for https://www.shakacode.com/react-on-rails-pro/ , you'll be up super quickly. Feel free to jump on our Slack and ask for this. Fairly easy.
@justin808 nvm for now, just learned how SSR works and it became easy to implement it on ruby
If this issue is still relevant, please comment.