From 4a19f66c31dfa419eaeaa9aefc18ce6eebacb564 Mon Sep 17 00:00:00 2001 From: JoeDow Date: Tue, 26 Aug 2025 00:22:05 +0800 Subject: [PATCH] script: mark image-related node dirty only when image resource loaded (#38916) Previously, we would always mark the image-related nodes as dirty whenever the fetch status of the image resources changed. However, the corresponding `ImageDisplayItem`s for these image resources are only generated after the image resources have been fully fetched and decoded. Therefore, we only mark the corresponding DOM nodes as dirty when the image resources are completely loaded, thereby reducing the occurrence of reflows. Signed-off-by: sharpshooter_pt --- components/script/dom/htmlimageelement.rs | 2 -- components/script/dom/window.rs | 6 ++++-- 2 files changed, 4 insertions(+), 4 deletions(-) diff --git a/components/script/dom/htmlimageelement.rs b/components/script/dom/htmlimageelement.rs index 8b5319d8ae2..2c25e621ea2 100644 --- a/components/script/dom/htmlimageelement.rs +++ b/components/script/dom/htmlimageelement.rs @@ -559,8 +559,6 @@ impl HTMLImageElement { self.upcast::() .fire_event(atom!("loadend"), can_gc); } - - self.upcast::().dirty(NodeDamage::Other); } fn process_image_response_for_environment_change( diff --git a/components/script/dom/window.rs b/components/script/dom/window.rs index 305f50dd122..db82b4ec0d4 100644 --- a/components/script/dom/window.rs +++ b/components/script/dom/window.rs @@ -646,8 +646,10 @@ impl Window { Entry::Occupied(nodes) => nodes, Entry::Vacant(_) => return, }; - for node in nodes.get() { - node.dirty(NodeDamage::Other); + if matches!(response.response, ImageResponse::Loaded(_, _)) { + for node in nodes.get() { + node.dirty(NodeDamage::Other); + } } match response.response { ImageResponse::MetadataLoaded(_) => {},