New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
ShadowDOM compatibility: Use child-to-parent observation instead of parent-to-child observation for constructing the scene graph from the HTML elements, then observe slot distribution in ShadowDOM roots. #40
Comments
The problem with parent-to-child observation of the tree is this is only a partial solution: it only works when the parent is one of LUME's custom elements ( I really want to be able to throw an error in order to make my API helpful. We need to find another way. So far, everything would work fine if all Shadow trees were open, but they are closed by default. |
|
I've decided only to convert to parent-to-child API, and for now not detect the error cases. An app will just silently fail. This may be improved in the future... |
Added childConnectedCallback and childDisconnectedCallback for subclasses to implement in order to run logic when a child is connected or disconnected. Update MotorHTMLBase and MotorHTMLNode classes. Basically added childConnectedCallback and childDisconnectedCallback methods to the base class to mirror the connections on the imperative side, which makes the API parent-to-child instead of child-to-parent. For now, the error state in which motor-nodes are attached to non-motor-node elements is ignored, and an app with such state will silently fail. It will be too complex and messy to make it work due to current Custom Elements API limitations. Some features that would help are described in issues #527 and #550 of w3c/webcomponents. This is partial work for issue #40. Next we need to make parents observe <content> or <slot> elements depending on version of the Custom Elements API in order to make ShadowDOM work.
Steps to make custom elements shadow-dom compatible:
That's all we need in order to render things in WebGL with shadow-dom |
Completed in bf52ca0, I've decided to support only ShadowDOM-v1. At this point I don't think it makes sense to support Custom Elements v0. |
Re-opened, because when I wrote this issue I was making my own WebGL renderer, so traversing the objects would work (traversing their ShadowDOM composed tree). But now that I'm using Three.js for WebGL, we can't simply traverse our own objects, instead we need to connect Three.js Object3D instances so that they are connected in the form of our composed tree; the Object3D instances are completely unaware of the composed tree. We also need to ensure that connected/disconnected reactions are based on the composed tree, not the light tree.
|
This was completed not too long ago. |
This will solve the problem of being able to detect when a
<lume-node>
element is improperly slotted/distributed into a ShadowDOM tree. Without this change (and with respect to elements that are distributed into a ShadowDOM tree), it is not possible to accurately construct our virtual scene graph because children elements observe their parent elements in order to determine how to attach virtual-scene-graph nodes, but closed ShadowDOM trees prohibit children from observing their parents (otherwise the ShadowDOM tree information would leak to the outer world which defeats ShadowDOM encapsulation).For more background info:
Currently, when a
<lume-node>
element is attached into the DOM, it checks to see if it's parent element that it was attached to ("connected" to in v1 API terms) is another<lume-node>
or<lume-scene>
element. If this is not the case, the child<lume-node>
element throws an error.However, this check is not possible when the
<lume-node>
element has been distributed into a ShadowDOM tree because from the perspective of the distributed<lume-node>
element, it's parent is the parent it was attached to outside of the ShadowDOM tree, and it can not get a reference to it's containing<content>
element (or<slot>
element in v1 API), and therefore it cannot check that the parent of the<content>
or<slot>
element is another<lume-node>
or<lume-scene>
element.To fix the problem we will have parent
<lume-node>
elements make the observation of their children instead of child<lume-node>
elements looking at their parents. Parent<lume-node>
elements that are inside of a ShadowDOM tree will have access to their<content>
or<slot>
element, and will be able to observe what gets distributed into there, and so the parent can throw the error based on the children it observes instead of the child throwing the error based on the parent it observes.We also need to double check that our behind-the-scenes virtual scene graph is connected based on parent-to-child observation as well, so this way the API will be easier to understand if the flow of observation is the same direction in the virtual scene graph as well as the DOM.It already is.cc @dmarcos, @cvan, @ngokevin, this will apply to a-frame elements too if they are to be ShadowDOM-compatible. I'm not sure if this is the case already (as far as parent-to-child observation). I know that a-frame isn't considering ShadowDOM yet, so HTML developers will run into this problem with A-Frame at some point when/if they decide to try using A-Frame in ShadowDOM trees.
The text was updated successfully, but these errors were encountered: