Zemanzo / web-marbles

Aims to recreate Marble Racing from the ground up, as a fully web based game
https://playmarbl.es/
GNU General Public License v3.0
23 stars 12 forks source link

React #280

Closed Zemanzo closed 4 years ago

Zemanzo commented 4 years ago

Since we aim to have a lot more UI, it would be a great step forwards if we could use a frontend framework. For that reason, I have implemented a React pipeline. Complete details can be found in the TDD, but in short: We create a base page on the server and attach a root component. The server renders the page (creates the HTML markup) and sends it to the client. The client can then hydrate the components to re-attach the interactivity to the components.

It also requires some new steps in the project setup:

I had to go for some suboptimal solutions here and there though:

Additional findings Whilst further experimenting and researching this topic, I stumbled upon the problem of passing server side data to the client. With SSR, we render the HTML on the server, which has to be hydrated on the client side to attach the correct interactivity (such as event listeners). This unfortunately also requires the data that was used to render it on the server. That means we'll have to somehow also pass along the raw data from the server to the client, which is rather wasteful since the data had already been rendered. A good example can be found here: https://developers.google.com/web/updates/2019/02/rendering-on-the-web#rehydration-issues

Related issues Makes the following issues easier:

199

197 maybe

185

158

155

148

91

90

89

88

Zemanzo commented 4 years ago

Should implement styled components properly for SSR https://styled-components.com/docs/advanced#server-side-rendering