SSR: Server-Side Rendering
See original GitHub issueHello,
I’m currently trying to use boardgame.io together with next.js.
Because the Server
part exports a Koa server, I went with this example to create a basic project:
https://github.com/zeit/next.js/tree/canary/examples/custom-server-koa
However, when I run the code, I get a window is not defined
error.
So I did some research and it’s of course because Next.js is SSR and the Client
component requires window
to be present. So I made it like this:
const App = Client({
game: Game,
multiplayer: true,
});
export default class Index extends React.Component {
state = {
isClient: false,
};
componentDidMount() {
this.setState({
isClient: true,
});
}
render() {
if (this.state.isClient) {
return <App />;
}
return 'Loading...';
}
}
According to next.js, the client side code only runs, after componentDidMount
has been triggered, so obviously window
should be available, but somehow it isn’t. Something inside Client
seems to run before that happens.
Issue Analytics
- State:
- Created 6 years ago
- Reactions:2
- Comments:10 (7 by maintainers)
Top Results From Across the Web
What is Server-Side Rendering? Definition and FAQs
Server -side rendering (SSR) is an application's ability to convert HTML files on the server into a fully rendered HTML page for the...
Read more >The Benefits of Server Side Rendering Over Client ... - Medium
SSR throughput of your server is significantly less than CSR throughput. For react in particular, the throughput impact is extremely large.
Read more >What is server-side rendering and how does it improve site ...
Server -side rendering (SSR) addresses the performance and search engine optimization issues of single-page JavaScript applications.
Read more >Server-Side Rendering (SSR) - Vue.js
During SSR, each request URL maps to a desired state of our application. There is no user interaction and no DOM updates, so...
Read more >Client-side vs. Server-side vs. Pre-rendering for Web Apps
An SSR/universal application can be really powerful if you have a large application with a lot of different pages. It allows your content...
Read more >
Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free
Top Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found
I got it working! 👏 Just submitted a PR, also managed to do a test so we dont break SSR in the future 😆
Maybe something like this could help… https://www.npmjs.com/package/window-or-global