mirror of
https://github.com/LadybirdBrowser/ladybird
synced 2026-04-26 01:35:08 +02:00
LibWeb: Skip full document style update in getComputedStyle if possible
Before calling update_style() for a getComputedStyle property access, we now check whether the target element actually needs a style update by walking the flat tree ancestor chain. If neither the element nor any of its ancestors have dirty style bits, and there are no document-level reasons to recalculate style, we skip the update_style() call entirely. We walk the flat tree (not the DOM tree) because style inheritance follows slot assignment -- slotted elements inherit from their assigned slot, not their DOM parent. This avoids unnecessary work when scripts access computed style properties on elements whose styles are already up-to-date, which is a common pattern on the web.
This commit is contained in:
committed by
Andreas Kling
parent
b270b2cacb
commit
4a7ca32af0
Notes:
github-actions[bot]
2026-02-13 09:24:01 +00:00
Author: https://github.com/awesomekling Commit: https://github.com/LadybirdBrowser/ladybird/commit/4a7ca32af07 Pull-request: https://github.com/LadybirdBrowser/ladybird/pull/7913 Reviewed-by: https://github.com/AtkinsSJ
@@ -560,7 +560,7 @@ Optional<StyleProperty> CSSStyleProperties::get_direct_property(PropertyNameAndI
|
||||
// always need update_layout() to ensure both style and layout tree are up to date.
|
||||
abstract_element.document().update_layout(DOM::UpdateLayoutReason::ResolvedCSSStyleDeclarationProperty);
|
||||
layout_node = abstract_element.layout_node();
|
||||
} else {
|
||||
} else if (abstract_element.document().element_needs_style_update(abstract_element)) {
|
||||
// Just ensure styles are up to date.
|
||||
abstract_element.document().update_style();
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user