DEV Community

Ibrahim ben Salah
Ibrahim ben Salah

Posted on

SSR in javascript is hard

I started working on Xania Web's Fastest JSX based Library since back in 2014.

Before that I was 90% backend 10y .NET developer and my focus has shifted since then more towards JavaScript. And because of my background I am hyped about the new trend shift towards backend, but...frontend has evolved and we don't want to loose the capabilities of our beloved libraries in favor of SSR. but it's hard.

SSR is mainly hard because of serialization of runtime state. Part of it is the need for javasript bundler at runtime. Basically we need to examine the data we are sending to the client, determine what types are used, track back where those types are defined in code (which I am not sure is even possible), create a hydration script which imports these types. And, it get even hard if we also want to serialize closures. After that framework specific handling can take over...which is relatively easy to do.

There are a couple of framework solutions with support for hydration (rehydration/resumability/lazy/partial,etc....) like SvelteKit, Next.JS, Qwik, Astro, Marko, etc... but it is sad to see that none allows an incremental / progressive adaption. They all are coupled to either a view library, routing or toolchain, I just want to use Vite and Xania and add Hydration to the mix.

Here is the challenge I am taking on:

  1. Is it possible to statiscally generate rehydration script at compile time? I am thinking of a solution that is using rollup transform plugin,
  2. Or otherwise, create a serializer, runtime bundler and hydration script.

I have little to no experience in this area, so any suggestion are very welcome.

Latest comments (0)