lambdanadasomething / fullstack-reframe

Clojurescript frontend with SSR (WIP)
https://lambdanadasomething.github.io/fullstack-reframe/
0 stars 0 forks source link

Server Side Render #2

Open lambdanadasomething opened 4 years ago

lambdanadasomething commented 4 years ago

It appears we would have to do this manually.

lambdanadasomething commented 4 years ago

Here's a detail:

The SPA itself is served as a bundled script in a <script> tag and is a static asset. What SSR does is to preload the "initial" DOM tree (more precisely, each URL correspond to a certain app state and hence to a specific view/DOM). However, we also need to set the appropriate initial app state somehow.

Again, it seems we have to achieve this manually. One possible mechanism: The state is encoded as json or some similar format, then injected into a separate <script> snippet that set a global javascript variable. The program is set to read from that and use it as the initial app state if present.

lambdanadasomething commented 2 years ago

This is much harder than expected, although there are many examples in the wild of people rolling their own SSR (which are old and likely unmaintained).

Seems SSR itself isn't too difficult - integrating it with all the libraries we are using without error is.

Copied from code comment:

SSR Trouble so far:

1) Dynamic import: repeatedly importing the same ns eventually makes this goes away 2) Reitit Routing 1: When using reitit's "easy" frontend integration, We didn't put it into re-frame's effect system... 3) Reitit Routing 2: reitit's easy frontend, href function only works in the browser env. We can use plain reitit for backend reverse routing. a) However, this implies that we need a way to detect current target at runtime. 4) Out of the three form of using EUI icons, the 2nd method (direct) Doesn't work.

We can summarize the following direction for a 2nd round:

And this is before 3rd round where the really funny stuff happen: