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
fix: children and childNodes not returning top-level slotted children #4098
Conversation
// ownerKey is undefined for such nodes | ||
const ownerKey = getNodeNearestOwnerKey(node); | ||
if (isNull(owner)) { | ||
return isUndefined(ownerKey); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Not so sure about this logic. If the owner is null
but ownerKey
is defined, then isNodeOwnedBy()
returns true
. By relaxing the input constraints, it seems that we're muddying the job of this function. Maybe this is a sign that we should be handling the light DOM case elsewhere?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think of this as node being owned by a shadowRoot or document (in which case it's null). It's owned by document, in case of light DOM parents.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Would having more tests for childNodes/children help build confidence? I suspect we don’t have a lot.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
For both childrenGetterPatched
and childNodesGetterPatched
, if there is no owner, then it means that the element or node is not shadowed, correct? If so, then it seems like we should immediately return getFilteredChildNodes(this)
instead of drilling down into getAllMatches()
and isNodeOwnedBy()
.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Makes sense! Done.
@@ -92,7 +92,11 @@ function shadowRootGetterPatched(this: Element): ShadowRoot | null { | |||
|
|||
function childrenGetterPatched(this: Element): HTMLCollectionOf<Element> { | |||
const owner = getNodeOwner(this); | |||
const childNodes = isNull(owner) ? [] : getAllMatches(owner, getFilteredChildNodes(this)); | |||
const filteredChildNodes = getFilteredChildNodes(this); | |||
// no need to filter nodes by owner in case of light DOM |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This also applies to root shadow DOM components:
// no need to filter nodes by owner in case of light DOM | |
// No need to filter by owner for non-shadowed elements |
// Elements slotted from top level light DOM into synthetic shadow | ||
// reach the slot tag from the shadow element first |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I didn't understand this comment. Are we short-circuiting here so that we don't need to traverse to the root?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The <slot>
element will belong to some other shadow root and check if the node
belongs to the owner of the <slot>
element. This check will fail and it won't return any elements.
Co-authored-by: Eugene Kashida <ekashida@gmail.com>
Details
Fixes #4076
Light DOM nodes aren't owned by any shadow root. We change
isNodeOwedBy
to account forowner
being null.Does this pull request introduce a breaking change?
Does this pull request introduce an observable change?
GUS work item