-
Notifications
You must be signed in to change notification settings - Fork 11
Add lazy hydration techniques: idle and view #75
Comments
For context: we are currently on a challenging quest, trying to find a way to hydrate components after a particular condition is fulfilled (e.g., CPU is idle, component is in view, etc.) This is intimately related to out-of-order hydration, which is another thing we want to achieve and why we are not using Some of the things we've tried are:
So far, with any of the approaches tested above, we've reached the same problem: once a new node appears in the virtual DOM —even though this node's component is a wrapper that simply renders In the second approach, choosing between
However, there's still hope. 😄 As preact is highly hackable, we could use Preact's Option Hooks API to make changes to the vDOM in a way that the DOM is preserved. @luisherranz has been involved in some conversations with Jason Miller (preact), who gave him some ideas we could explore. We will be working on that next week. 🤞 @luisherranz, feel free to expand this if you feel something is missing. 🙂 |
Super preliminary yet, but I made it work by manually mutating the vdom as suggested by Jason: const clientCompParent = window.root.__k.__k[0].__k[2];
const clientComp = h(ClientComponent);
clientComp.__b = clientCompParent.__b + 1;
clientCompParent.__k.forEach((child) => {
child.__b += 1;
child.__o = clientComp;
});
clientComp.__k = clientCompParent.__k;
clientComp.__o = clientCompParent;
clientCompParent.__k = [clientComp]; |
Even though mutating the previous vdom before the rerender works, doing so on the fly for an undetermined number of internal components is not possible at the moment because in We need to know the exact shape of the new vdom before triggering the rerendering. As updating the vdom without updating the DOM is not possible, another possible approach might be:
But this starts getting too complex and convoluted. I'd leave it for now, keep exploring other things, and come back to this later. |
Another wild idea: annotate in the DOM the number of component vnodes during the SSR, then insert as many innocuous wrappers as needed in the dom -> vdom step. |
Now that #124 has landed, maybe we can revisit this for sites without client-side navigations. |
Closed in favor of |
We want to add different hydration techniques for blocks as we did for the Island Hydration approach in #12.
At this moment, we can start by adding
view
andidle
and keep adding more in the future.The text was updated successfully, but these errors were encountered: