-
Notifications
You must be signed in to change notification settings - Fork 11
Wrapperless hydration alternative: Directives hydration #60
Comments
I did a quick example using https://codesandbox.io/s/preact-markup-interactive-blocks-using-children-wrapper-j576q0 Some caveats regarding DX would be these:
I haven't considered performance yet, but I guess that locating the children of a component and placing them in their correct position in the vDOM could be done while processing DOM nodes instead of doing that once the vDOM subtree has been generated. Anyway, I'm sure there are other possible approaches we can explore and discuss (e.g. using an attribute in children nodes). Feel free to share feedback or more ideas. 😄 |
That's promising. Thank you, David 🙂 EDIT: We moved the children/slot conversation to #62 |
That looks interesting! One aspect that could get tricky is compatibility with existing plugins or scripts that work with the DOM on the page. Like an image carousel plugin for a simple example.
Another potential issue is interference between two separate plugins. For example, they could both add a global Provider with a redux store that's not namespaced. Most of this can probably be solved with documenting rules and expectations, since these plugins would be new developments, and also by providing safe APIs for common conflict points like the context provider example. |
EDIT: We moved the children/slot conversation to #62 |
EDIT: We moved the children/slot conversation to #62 |
I had a conversation with Preact's core team in their Slack regarding the use of Preact's internals that is relevant for this point. The summary is here: |
@yscik: I don't think there is any significant change from what is already happening with the islands hydration. I made a video because these types of things are not easy to explain with words. Please let me know if you think there's something else going on that I missed in terms of compatibility with existing scripts. |
Thanks for the explanation! I missed the fact that the static nodes won't be replaced at all because this is hydration. That resolves my concerns :) For compatibility with external scripts, I was worried only about the static parts of the site, I wouldn't expect things not breaking when they meddle in the React components. |
Perfect then. Thanks, Peter! |
We've opened a new Tracking Issue to start working on this: From now on, we'll publish updates on what we are working there, but we can keep using this issue for the conversation related to the pattern design. |
Closed as this was already implemented. |
I've been thinking about how to get rid of wrappers because the
display: contents
solution doesn't seem to be compatible with classic themes: #49.One solution could be to iterate over the DOM and build a "static virtual DOM" of the full page. Something like this:
createElement
: https://codesandbox.io/s/react-vdom-from-document-body-itkew3?file=/src/index.jsh
: https://codesandbox.io/s/preact-vdom-from-document-body-erz79jAs we iterate the DOM, we could check for the View components, and add them to the virtual DOM:
Although for this to work properly, we need to avoid adding the nodes that belong to the View component as static virtual nodes or they would appear duplicated. A simple way to do that would be to find the
children
of the View component and ignore the rest.This approach could support hydration techniques. It could work by checking the value of a prop (i.e.,
wp-block-hydration
) and creating static virtual nodes if the conditions are not met yet. Then, once the conditions are met, replace the static virtual nodes with the virtual nodes generated by the View component.This method would have some advantages over the current one:
setTimeout
s.Provider
may not work with oneProvider
per island, like for example Recoil.And one disadvantage:
The preact-markup package is doing something similar to this approach. I've used it to emulate this, including the client-side navigations:
https://www.loom.com/share/35d882062e2447f3b2b9cae78cb75127
You can play with that codesanbox here: https://codesandbox.io/s/preact-markup-interactive-blocks-6knev6?file=/src/index.js
Credits to Jason Miller and
preact-markup
for a big part of the inspiration.I would start trying this with Preact, and doing so in two steps:
hydrate
.If it works, we could try doing the hydration during the generation of the static virtual DOM to optimize the performance because, at that moment, you already know the vNode <-> DOM node relation.
The text was updated successfully, but these errors were encountered: