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 <ibluegalaxy_taoj@163.com>
This commit is contained in:
JoeDow 2025-08-26 00:22:05 +08:00 committed by GitHub
parent cf13fd4628
commit 4a19f66c31
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
2 changed files with 4 additions and 4 deletions

View file

@ -559,8 +559,6 @@ impl HTMLImageElement {
self.upcast::<EventTarget>()
.fire_event(atom!("loadend"), can_gc);
}
self.upcast::<Node>().dirty(NodeDamage::Other);
}
fn process_image_response_for_environment_change(

View file

@ -646,9 +646,11 @@ impl Window {
Entry::Occupied(nodes) => nodes,
Entry::Vacant(_) => return,
};
if matches!(response.response, ImageResponse::Loaded(_, _)) {
for node in nodes.get() {
node.dirty(NodeDamage::Other);
}
}
match response.response {
ImageResponse::MetadataLoaded(_) => {},
ImageResponse::Loaded(_, _) |