add support for (progressive) hydration for compatible renderers (globalThis
for state?)
#880
Open
1 of 5 tasks
Labels
Milestone
Type of Change
Summary
At it simplest, in the context of server or pre-rendering, hydration is the ability for a client side library to re-use the existing HTML (often generated by same client library on the server side) so that on load of the page, the client side library can avoid having to do any DOM manipulation and just build up its internal state / event handers from the existing inert HTML on the page already. This really help with things like Cumulative Layout Shift (CLI) and Time to Interactive (TTI) which are a part of core web vitals.
I think this should be a feature turned off by default, and that can be enabled via greenwood.config.js.
Details
Libraries like Lit provide such a capability (which will be the pilot for this particular issue though I do want roll our own at some point in service of #548 ) but in the context where data comes into play, that same data must be present in the client as well to ensure that server and client HTML match.
Thus Greenwood needs to expose / inject data somehow into the system we have set up, or alter it to be more accommodating. For static prerendering, this may require another approach since it won't be coming from a [route].js file. My initial hunch is to follow a similar convention as per
interpolateFrontmatter
and just stuff everything intoglobalThis
as per #1005 , e.g.Will also want to add this for WCC using
metadata
Also should support different strategies like eager or lazy loading.
Coming out of https://github.com/ProjectEvergreen/greenwood/pull/1157/files#r1359495833, I think we have the mechanism by which to orchestrate this now, and it can be opt-in without any specification configuration. The gist being any SSR page can export a
loader
function, which Greenwood can use toloader
function allows us to serialize the props for further hydration at runtime.That said, if SSR pages never have their code sent to the client, is any of this needed? A page could also SSR the data right into their child components like in this example?, e.g.
Could be worth looking into WCCG Context Community Protocol. We can even consider making it opt-in, e.g.
Or else maybe there is a use case to ship the SSR page code to the client? 🤔
The pilot for this can be Lit's SSR hydration support added in #1201
and WCC
The text was updated successfully, but these errors were encountered: