r/Clojure • • Sep 13 '17

PWAs built in ClojureScript?

Been reading through yet another case study about migrating a website to Progressive Web App architecture in JS (https://medium.com/dev-channel/treebo-a-react-and-preact-progressive-web-app-performance-case-study-5e4f450d5299) and it got me thinking are there any known PWAs in production built in ClojureScript?

Also, is there anything that cljs might lack in order to be able to ship a PWA? We already have code splitting and server side rendering.

17 Upvotes

13 comments sorted by

2

u/dustingetz Sep 14 '17 edited Sep 14 '17

Hyperfiddle is a progressive web app, all possible states can be SSRed

The hard part is that React.js rendering takes significant compute, its fine when each user does their own rendering, but when hosting renders for the world paying 200ms per user per dynamic page is not a great place to be and single-threaded Nodejs does not make this easy, there's no easy way yet to chunk up this 200ms of work to make it nonblocking, you need a nodejs cluster. React Fiber should help in theory but details are unclear. There is a lot of future work to be done to make React.js PWAs work out, its not as simple as just SSR it once and stick a CDN in front of it like a blog.

Hyperfiddle does not solve this yet, I am collecting links about this here if anyone would like to contribute: https://www.reddit.com/r/reactssr/

Oh and did I say 200ms per dynamic page? Its more like 10 seconds for some pages. I do believe we can get that down to milleseconds, but it requires being extremely careful with how you code your React components; fast performance is possible but is nowhere close to free and tiny little things can blow the whole page perf. The final answer is probably going to involve saving the virtual dom in server session and using reactive forceUpdate on the server, just like how the browser gets fast perf. So that means sticky sessions and React.js monkey patches.

1

u/roman01la Sep 14 '17

Did you mean you are doing SSR in Node? It's super fast on JVM if you have a DSL such as Hiccup that can be interpreted. Also Fiber does very good job actually, rendering time is decreased dramatically.

1

u/dustingetz Sep 14 '17

I think you need to actually evaluate the react.js views. The whole app isn't hiccup, there is third party react code from npm on the page etc

1

u/roman01la Sep 14 '17

Oh, in that case it's unfortunate. But in general it was shown that full-page SSR doesn't buy much, so at least rendering a "shell" would be fine.

1

u/dustingetz Sep 14 '17

what do you mean "it was shown" can you post some links?

1

u/roman01la Sep 14 '17

I'd suggest to read the post that I refered to above and every other post from Addy Osmani on PWA case studies.

1

u/dustingetz Sep 22 '17 edited Sep 22 '17

Thanks that was a good read. You probably know this already but fiber has new ssr apis:

https://github.com/facebook/react/blob/master/docs/docs/reference-react-dom-node-stream.md#rendertonodestream - that sounds async to me?

https://github.com/facebook/react/pull/10339/files - looks like it will help with time to interactivity

2

u/Savo4ka Sep 14 '17 edited Sep 14 '17

Here is a link to doing Clojurescript react SSR without Node or React. https://solovyov.net/en/2017/server-side-rendering/

1

u/dustingetz Sep 14 '17

I was thinking about this some more, consider markdown rendering, something extensible like showdown. Non-hiccup view code is everywhere

2

u/lilactown Sep 14 '17

Yikes - that's not what my preliminary tests with React SSR has shown. How heavy a page is this? Are you creating bundles for these pages or relying on Node.js' require to do the necessary resolving/importing of code?

What I found running some simple pages/apps through an express server with babel-loader set up was that the initial load was ~100-200ms, but subsequent loads were ~30ms: https://github.com/Lokeh/react-template-server

Where I've run into issues is with stuff like css-modules and require-ing images, which obviously doesn't work in node... or something like ClojureScript which doesn't output Node.js-compatible modules.

In those cases I'm afraid I might need to bundle/compile for the server-side and then parse the whole bundle, which I would imagine is much less performant.

1

u/dustingetz Sep 14 '17

My pages are facebook-heavy. I'm not really sure what you're talking about. It's the execution time of ReactDOM.renderToString which is expensive and blocking.

1

u/TotesMessenger Sep 14 '17

I'm a bot, bleep, bloop. Someone has linked to this thread from another place on reddit:

If you follow any of the above links, please respect the rules of reddit and don't vote in the other threads. (Info / ^Contact)