Closed Zasa-san closed 6 months ago
We decided to load basic atom store data with a similar technique to what we do for redux. Given the complexities of our server side rendering it is not feasible to have loaders earlier in the component tree (where we set the atom store and construct the routes) to handle data requesting for the first render.
Currently, to construct our routes we need information from settings and the current user if there is one. Without this info we cannot create the routes at entry-client.tsx
or entry-server.tsx
, the latter already is loading this info. By passing that information through Root.js
injected in the window
object we can construct our atom store independently from redux and use it to generate the first client side render. We would do the same with translations in the associated issue #6691.
This is not a bad strategy as long as we don’t load a massive amount of data since it pollutes the html. In the future, once we get rid of redux and the legacy routes, we can look for alternatives to communicate this data needed by the client for the first render. Barring a complete revamp of our current SSR and CSR (which is very complex to do with the dependencies that our legacy routes have) I think this is the best approach to set the initial state of the app and construct the routes and atom store.
@konzz @mfacar
While developing #6691 we noticed the need to use
loader
functions fromreact-router
to fetch translations data, without having to rely on our current method that depends on using theredux
store. This would also allow us to set our new atom state management in the client on first load, again, without using theredux
store.