Bug 1076784 - Don't remove binding when shadow root host is removed from tree. r=smaug
--- a/content/base/src/Element.cpp
+++ b/content/base/src/Element.cpp
@@ -1484,17 +1484,19 @@ Element::UnbindFromTree(bool aDeep, bool
// Begin keeping track of our subtree root.
SetSubtreeRootPointer(aNullParent ? this : mParent->SubtreeRoot());
}
if (document) {
// Notify XBL- & nsIAnonymousContentCreator-generated
// anonymous content that the document is changing.
- if (HasFlag(NODE_MAY_BE_IN_BINDING_MNGR)) {
+ // Unlike XBL, bindings for web components shadow DOM
+ // do not get uninstalled.
+ if (HasFlag(NODE_MAY_BE_IN_BINDING_MNGR) && !GetShadowRoot()) {
nsContentUtils::AddScriptRunner(
new RemoveFromBindingManagerRunnable(document->BindingManager(), this,
document));
}
document->ClearBoxObjectFor(this);
if (GetCustomElementData()) {
--- a/content/base/src/nsGenericDOMDataNode.cpp
+++ b/content/base/src/nsGenericDOMDataNode.cpp
@@ -581,19 +581,21 @@ nsGenericDOMDataNode::UnbindFromTree(boo
if (aNullParent || !mParent->IsInShadowTree()) {
UnsetFlags(NODE_IS_IN_SHADOW_TREE);
// Begin keeping track of our subtree root.
SetSubtreeRootPointer(aNullParent ? this : mParent->SubtreeRoot());
}
- if (document) {
+ if (document && !GetContainingShadow()) {
// Notify XBL- & nsIAnonymousContentCreator-generated
// anonymous content that the document is changing.
+ // Unlike XBL, bindings for web components shadow DOM
+ // do not get uninstalled.
if (HasFlag(NODE_MAY_BE_IN_BINDING_MNGR)) {
nsContentUtils::AddScriptRunner(
new RemoveFromBindingManagerRunnable(document->BindingManager(), this,
document));
}
}
nsDataSlots *slots = GetExistingDataSlots();
--- a/layout/reftests/webcomponents/reftest.list
+++ b/layout/reftests/webcomponents/reftest.list
@@ -11,8 +11,9 @@ pref(dom.webcomponents.enabled,true) ==
pref(dom.webcomponents.enabled,true) == remove-insertion-point-1.html remove-insertion-point-1-ref.html
pref(dom.webcomponents.enabled,true) == nested-insertion-point-1.html nested-insertion-point-1-ref.html
pref(dom.webcomponents.enabled,true) == basic-shadow-element-1.html basic-shadow-element-1-ref.html
pref(dom.webcomponents.enabled,true) == nested-shadow-element-1.html nested-shadow-element-1-ref.html
pref(dom.webcomponents.enabled,true) == update-dist-node-descendants-1.html update-dist-node-descendants-1-ref.html
pref(dom.webcomponents.enabled,true) random-if(B2G&&browserIsRemote) == input-transition-1.html input-transition-1-ref.html # Failure on B2G emulator due to Bug 1018381
pref(dom.webcomponents.enabled,true) == dynamic-insertion-point-distribution-1.html dynamic-insertion-point-distribution-1-ref.html
pref(dom.webcomponents.enabled,true) == dynamic-insertion-point-distribution-2.html dynamic-insertion-point-distribution-2-ref.html
+pref(dom.webcomponents.enabled,true) == remove-append-shadow-host-1.html remove-append-shadow-host-1-ref.html
new file mode 100644
--- /dev/null
+++ b/layout/reftests/webcomponents/remove-append-shadow-host-1-ref.html
@@ -0,0 +1,6 @@
+<!DOCTYPE html>
+<html>
+ <body>
+ <div>inside shadow DOM</div>
+ </body>
+</html>
new file mode 100644
--- /dev/null
+++ b/layout/reftests/webcomponents/remove-append-shadow-host-1.html
@@ -0,0 +1,17 @@
+<!DOCTYPE html>
+<html>
+ <head>
+ </head>
+ <body>
+ <div id="container"><div id="host"></div></div>
+ <script>
+ var host = document.getElementById("host");
+ var root = host.createShadowRoot();
+ root.innerHTML = 'inside shadow DOM';
+
+ var container = document.getElementById("container");
+ container.removeChild(host);
+ container.appendChild(host);
+ </script>
+ </body>
+</html>