self defined progressive hydration for custom elements #3
Labels
documentation
Improvements or additions to documentation
expirement
help wanted
Extra attention is needed
Milestone
Overview
Coming out of conversation around hydration within the WCCG, was thinking about what might be possible if we could intercept the
customElements.define
call at the browser level? Maybe we could use it to let a WebComponent bootstrap itself with its own intersection observer logic, so instead of having to defining everything via attributes and / or some framework glue layer, e.gA custom element could do this itself via a contract / community protocol, like using a static method or member, which could initialize its own Intersection Observer maybe?
However, this presumably introduces a chicken and the egg scenario though because at this point a CE is calling
customElements.define
, the JS would already have been loaded on to the point, which kind of defeats the purpose somewhat.So there will still need to be a way to decouple the "intersection" trigger from the component itself, which I suppose does benefit a compiler based tool, so there is that. 😄
Details
My thought there is that for the above example, we could extract the static method from the class and just providing that to be include that at runtime.
And then we inject just that function into the runtime. So in theory, there is no
wcc
overhead, it is purely user based.What is neat about this I think, is that you can now open up levels and degrees of hydration aside from just top down which would be a limitation of having to express the attributes everywhere up front. So depending on how many
Additional thoughts / goals
lazyDefine
proposalhydrate
since this would push all that JavaScript to the runtime (a la Svelte). Which probably won't be much in the grand scheme of things, be entirely coming from userland, and entirely opt-in.hydrate
out of the custom elements class definition as well to avoid shipping the bytes at runtimeOpened an issue in the WCCG's Community Protocols repo.
The text was updated successfully, but these errors were encountered: