From f6b98d5c5614ef820428b96f4282db14a6ed2434 Mon Sep 17 00:00:00 2001 From: JoeDow Date: Mon, 14 Jul 2025 19:21:45 +0800 Subject: [PATCH] layout: dirty parent node with NodeDamage::ContentOrHeritage when text content changed (#38057) This change aims to reduce the scope of incremental box tree construction. Previously, when text content changed, the parent node would always be marked as requiring box tree reconstruction; now, it is adjusted to only mark the parent node as needing to recollect its box tree children. Testing: This should not change observable behavior and is thus covered by existing WPT tests. Signed-off-by: sharpshooter_pt --- components/script/dom/node.rs | 8 +++++++- 1 file changed, 7 insertions(+), 1 deletion(-) diff --git a/components/script/dom/node.rs b/components/script/dom/node.rs index f0e490cf495..b3d492a4ac5 100644 --- a/components/script/dom/node.rs +++ b/components/script/dom/node.rs @@ -817,7 +817,13 @@ impl Node { match self.type_id() { NodeTypeId::CharacterData(CharacterDataTypeId::Text(TextTypeId::Text)) => { - self.parent_node.get().unwrap().dirty(damage) + // For content changes in text nodes, we should accurately use + // [`NodeDamage::ContentOrHeritage`] to mark the parent node, thereby + // reducing the scope of incremental box tree construction. + self.parent_node + .get() + .unwrap() + .dirty(NodeDamage::ContentOrHeritage) }, NodeTypeId::Element(_) => self.downcast::().unwrap().restyle(damage), NodeTypeId::DocumentFragment(DocumentFragmentTypeId::ShadowRoot) => self