Repository: servo/servo
File: components/script/dom/html/htmldetailselement.rs (Rust)

Code before:
                .register_details_element(self);
        }

        let was_already_in_shadow_tree = context.is_shadow_tree == IsShadowTree::Yes;
        if !was_already_in_shadow_tree {
            if let Some(shadow_root) = self.containing_shadow_root() {
                shadow_root
                    .details_name_groups()
                    .register_details_element(self);
            }
        }

        self.ensure_details_exclusivity(ExclusivityConflictResolution::CloseThisElement);
    }

    fn unbind_from_tree(&self, context: &UnbindContext, can_gc: CanGc) {
        self.super_type().unwrap().unbind_from_tree(context, can_gc);

        if context.tree_is_in_a_document_tree && !self.upcast::<Node>().is_in_a_document_tree() {
            self.owner_document()
                .details_name_groups()
                .unregister_details_element(self.Name(), self);
        }

        if !self.upcast::<Node>().is_in_a_shadow_tree() {
            if let Some(old_shadow_root) = self.containing_shadow_root() {
                // If we used to be in a shadow root, but aren't anymore, then unregister this details
                // element.
                old_shadow_root
                    .details_name_groups()
                    .unregister_details_element(self.Name(), self);
            }
        }
    }
}


Review comment (suggestion):
```suggestion
        // Step 1. Ensure details exclusivity by closing the given element if needed given insertedNode.
        self.ensure_details_exclusivity(ExclusivityConflictResolution::CloseThisElement);
```

Code after:
    /// <https://html.spec.whatwg.org/multipage/#the-details-element:html-element-insertion-steps>
    fn bind_to_tree(&self, context: &BindContext, can_gc: CanGc) {
        self.super_type().unwrap().bind_to_tree(context, can_gc);

        self.update_shadow_tree_contents(can_gc);
        self.update_shadow_tree_styles(can_gc);

        if context.tree_is_in_a_document_tree {
            // If this is true then we can't have been in a document tree previously, so
            // we register ourselves.
            self.owner_document()
                .details_name_groups()
                .register_details_element(self);
        }

        let was_already_in_shadow_tree = context.is_shadow_tree == IsShadowTree::Yes;
        if !was_already_in_shadow_tree {
            if let Some(shadow_root) = self.containing_shadow_root() {
                shadow_root
                    .details_name_groups()
                    .register_details_element(self);
            }
        }

        // Step 1. Ensure details exclusivity by closing the given element if needed given insertedNode.
        self.ensure_details_exclusivity(ExclusivityConflictResolution::CloseThisElement);
    }

    fn unbind_from_tree(&self, context: &UnbindContext, can_gc: CanGc) {
        self.super_type().unwrap().unbind_from_tree(context, can_gc);

        if context.tree_is_in_a_document_tree && !self.upcast::<Node>().is_in_a_document_tree() {
            self.owner_document()
                .details_name_groups()
                .unregister_details_element(self.Name(), self);
        }

        if !self.upcast::<Node>().is_in_a_shadow_tree() {
            if let Some(old_shadow_root) = self.containing_shadow_root() {
                // If we used to be in a shadow root, but aren't anymore, then unregister this details
                // element.
                old_shadow_root
                    .details_name_groups()
                    .unregister_details_element(self.Name(), self);
            }
        }
    }
}