You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
The current approach for server-side rendering as illustrated by the SSR example is difficult to implement with popular templates like Create React App. This is primarily due to the differences between the top-level renderers on the server-side vs. the client-side. Is it possible to change this approach to simplify SSR?
This is not a v0.x issue.
I have searched the issues of this repository and believe that this is not a duplicate.
Expected Behavior
The server-side render should work by starting with ./build/index.html. This makes sure that we are automatically using one or more chunks created by the normal build process. Here's how I have seen it done in most SSR articles:
app.get('^/$', (req, res) => {
// Point to the html file created by CRA's build tool
const indexFile = path.resolve('./build/index.html');
fs.readFile(indexFile, 'utf8', (err, indexHtml) => {
if (err) {
console.error('Something went wrong:', err);
return res.status(500).send('Oops, better luck next time!');
}
// Render the app as an HTML string
const appHtml = ReactDOMServer.renderToString(<App />);
// Inject the rendered app into our html and send it
return res.send(
indexHtml.replace(
'<div id="root"></div>',
`<div id="root">${appHtml}</div>`
)
);
});
});
Current Behavior
In the current example, the client and server side renders are different. Specifically, the server-side render assumes that the JavaScript bundle produced by the build process is build/bundle.js. See the code below from server.js:
We cannot assume this. For example, Create React App produces multiple chunks with dynamic names like main.0705bcc6.chunk.js and 1.f5da4321.chunk.js. Hence the current SSR approach will not work. It would be much easier if we can work with the build/index.html produced by Create React App and modify it to produce the server-side render.
The text was updated successfully, but these errors were encountered:
IMO if SSR is important to you, you are better using a framework geared towards SSR, as create-react-app is not. Next.js or Fusion.js would be a great option. I'm currently working with another collaborator on an implementation of MUI SSR within a single line of code for Fusion.js, using this plugin.
The current approach for server-side rendering as illustrated by the SSR example is difficult to implement with popular templates like Create React App. This is primarily due to the differences between the top-level renderers on the server-side vs. the client-side. Is it possible to change this approach to simplify SSR?
Expected Behavior
The server-side render should work by starting with
./build/index.html
. This makes sure that we are automatically using one or more chunks created by the normal build process. Here's how I have seen it done in most SSR articles:Current Behavior
In the current example, the client and server side renders are different. Specifically, the server-side render assumes that the JavaScript bundle produced by the build process is
build/bundle.js
. See the code below from server.js:We cannot assume this. For example, Create React App produces multiple chunks with dynamic names like
main.0705bcc6.chunk.js
and1.f5da4321.chunk.js
. Hence the current SSR approach will not work. It would be much easier if we can work with thebuild/index.html
produced by Create React App and modify it to produce the server-side render.The text was updated successfully, but these errors were encountered: