Skip to content
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

Merged
merged 7 commits into from
Jan 31, 2018
Merged

Templatize: remove slots when hiding children #4993

merged 7 commits into from
Jan 31, 2018

Conversation

sorvell
Copy link
Contributor

@sorvell sorvell commented Dec 15, 2017

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.

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.
@TimvdLippe
Copy link
Contributor

While it works, it does feel weird to remove these slots. Would this solution still work if you change the light dom nodes?

} else if (n.localName === 'slot') {
if (hide) {
n.__polymerParent__ = n.parentNode;
n.__polymerSibling__ = n.nextSibling;
Copy link
Member

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?

Copy link
Contributor

@TimvdLippe TimvdLippe left a 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

Steven Orvell added 2 commits January 29, 2018 12:08
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.
const parent = n.__polymerParent__;
const replace = n.__polymerReplaced__;
if (parent && replace) {
parent.replaceChild(n, n.__polymerReplaced__);
Copy link
Contributor

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)

@sorvell sorvell merged commit 62fd4c5 into master Jan 31, 2018
@sorvell sorvell deleted the dom-if-slot branch January 31, 2018 22:05
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants