HTML Custom Elements v1 - Nested custom elements and compositon - The parent element can' see it's children in connectedcallback
Reported by
ephemere...@gmail.com,
Oct 21 2016
|
||||
Issue description
Chrome Version : Version 54.0.2840.59 m (64-bit)
Other browsers tested: None, Custom Elements v1 is only implemented in Chrome yet.
What steps will reproduce the problem?
See the attached HTML code file. Tested with Chrome dev tools.
*****First - Expected behavior and working
(1) Create 1 custom element that will become a container.
(2) Nest native HTML elements in the container:
<custom-container>
<child></child>
...
<child></child>
</custom-container>
(3) In the container's connectedCallback method modify the children (for instance their innerHTML).
(4) Load the page and break into the container's connectedCallback method.
Expected behavior: The container's connectedCallback CAN SEE all of it's children and can perform actions on them.
This is the expected behavior for a container that manipulates it's children and is essential for composition.
Three ways to verify this, first break into the container's connectedCallback method:
a) Output the chidren node in the console
b) Simply look at the content of the container in the Elements view.
c) Let it run and look at the HTML page results. Children will be modified.
*****Second - Unexpected behavior and NOT working
(1) Create 2 custom elements, one the container, the other the child.
(2) Nest these elements like before
<custom-container>
<custom-child></custom-child>
...
<custom-child></custom-child>
</custom-container>
(3) In the container's connectedCallback method modify the children (for instance their innerHTML).
(4) Load the page and break into the container's connectedCallback method.
Unexpected behavior: The container's connectedCallback can't see any of it's children.
This is an unexpected behavior and prevents the container from manipulating it's children.
Putting a break point in connectedCallback we can clearly see that the container is empty (console or Elements view).
The output of the HTML page clearly shows that the container could not manipulate it's children.
Question:
-Is there another callback that should be used instead for custom elements when using composition? I could not find any.
*****Important: The creation sequence of custom elements using composition SHOULD NOT differ from the native ones, it defies the whole purpose of having custom elements behaving like native ones and will lead to disastrous side effects.
For now I can't implement custom elements composition and my project is on hold.
,
Oct 21 2016
,
Oct 24 2016
Blink>WebComponents is deprecated.
,
Oct 24 2016
CCing domenic and esprehn FYI re: custom elements design, microtask control, etc. I'm closing this as WontFix because I think this is working as intended and per the spec, even though the behavior is surprising. domenic can sanity check me on that. Some contributors to the spec considered a callback for "end tag parsed" which would be a good time to inspect children if you were doing "one shot" processing of children, however IIRC the decision was to not add this callback yet. If you want a custom element's behavior to depend on its children you should use a MutationObserver or have the children coordinate with the container through events/methods/etc. |
||||
►
Sign in to add a comment |
||||
Comment 1 by ephemere...@gmail.com
, Oct 21 20161.5 KB
1.5 KB View Download