diff --git a/lib/utils/templatize.html b/lib/utils/templatize.html
index 52f9f05d13..319ea1a78e 100644
--- a/lib/utils/templatize.html
+++ b/lib/utils/templatize.html
@@ -176,15 +176,18 @@
} else if (n.localName === 'slot') {
if (hide) {
n.__polymerParent__ = n.parentNode;
- n.__polymerSibling__ = n.nextSibling;
- n.parentNode.removeChild(n);
+ n.__polymerReplaced__ = new Comment('hidden-slot');
+ n.parentNode.replaceChild(n.__polymerReplaced__, n);
} else {
const parent = n.__polymerParent__;
- if (parent) {
- parent.insertBefore(n, n.__polymerSibling__ || null);
+ const replace = n.__polymerReplaced__;
+ if (parent && replace) {
+ parent.replaceChild(n, n.__polymerReplaced__);
}
}
- } else if (n.style) {
+ }
+
+ else if (n.style) {
if (hide) {
n.__polymerDisplay__ = n.style.display;
n.style.display = 'none';
diff --git a/test/unit/dom-if-elements.html b/test/unit/dom-if-elements.html
index ea877ef653..a077feea22 100644
--- a/test/unit/dom-if-elements.html
+++ b/test/unit/dom-if-elements.html
@@ -193,11 +193,11 @@
- stuff
-
-
+ stuff
+ hi
+
{{text}}
-
+