diff --git a/Userland/Libraries/LibWeb/DOM/Node.cpp b/Userland/Libraries/LibWeb/DOM/Node.cpp index c55999285a..3c147f58f7 100644 --- a/Userland/Libraries/LibWeb/DOM/Node.cpp +++ b/Userland/Libraries/LibWeb/DOM/Node.cpp @@ -176,10 +176,22 @@ void Node::set_node_value(const String& value) void Node::invalidate_style() { - for_each_in_inclusive_subtree_of_type([&](auto& element) { - element.set_needs_style_update(true); + for_each_in_inclusive_subtree([&](Node& node) { + node.m_needs_style_update = true; + if (node.has_children()) + node.m_child_needs_style_update = true; + if (auto* shadow_root = node.is_element() ? static_cast(node).shadow_root() : nullptr) { + shadow_root->m_needs_style_update = true; + if (shadow_root->has_children()) + shadow_root->m_child_needs_style_update = true; + } return IterationDecision::Continue; }); + for (auto* ancestor = parent_or_shadow_host(); ancestor; ancestor = parent_or_shadow_host()) { + if (ancestor->m_child_needs_style_update) + break; + ancestor->m_child_needs_style_update = true; + } document().schedule_style_update(); }