-
Notifications
You must be signed in to change notification settings - Fork 2k
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
Templatize: remove slots when hiding children #4993
Conversation
Fixes #4977. When templatized content is hidden (via `_showHideChildren`) as in `dom-if` top level `<slot>` elements are now removed instead of being hidden. This ensures that assigned nodes are not displayed in false-y dom-if elements.
While it works, it does feel weird to remove these slots. Would this solution still work if you change the light dom nodes? |
lib/utils/templatize.html
Outdated
} else if (n.localName === 'slot') { | ||
if (hide) { | ||
n.__polymerParent__ = n.parentNode; | ||
n.__polymerSibling__ = n.nextSibling; |
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.
If the sibling was removed (e.g. due to dom-if
going false) then the slot would never come back.
May be better to replaceChild with a non-slot?
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.
Looking at this again, it makes more sense to me. Echoing @kevinpschaaf comment regarding the sibling. Not sure how we can handle that. We somehow have to keep track of where we were in the tree and insert it there. Replacing with non-slot and hide that seems like a 👌 solution
This change makes the slot not depend on its nextSibling being stable in dom which is problematic if, for example, its nextSibling is a restamping dom-if which becomes false.
lib/utils/templatize.html
Outdated
const parent = n.__polymerParent__; | ||
const replace = n.__polymerReplaced__; | ||
if (parent && replace) { | ||
parent.replaceChild(n, n.__polymerReplaced__); |
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.
Nit: can be parent.replaceChild(n, replace)
Fixes #4977. When templatized content is hidden (via
_showHideChildren
) as indom-if
top level<slot>
elements are now removed instead of being hidden. This ensures that assigned nodes are not displayed in false-y dom-if elements.