LibWeb: Update m_inline_style when element style attribute is removed

Previously we would just throw it away and construct a new (empty) one
when required. This doesn't work as any existing references to the old
instance will contain out of date information. Now we retain and update
the existing instance instead.
This commit is contained in:
Callum Law 2025-06-09 16:42:53 +12:00 committed by Sam Atkins
commit 610ad25555
Notes: github-actions[bot] 2025-06-09 11:08:02 +00:00
3 changed files with 21 additions and 14 deletions

View file

@ -3637,20 +3637,13 @@ void Element::attribute_changed(FlyString const& local_name, Optional<String> co
if (m_class_list)
m_class_list->associated_attribute_changed(value_or_empty);
} else if (local_name == HTML::AttributeNames::style) {
if (!value.has_value()) {
if (m_inline_style) {
m_inline_style = nullptr;
set_needs_style_update(true);
}
} else {
// https://drafts.csswg.org/cssom/#ref-for-cssstyledeclaration-updating-flag
if (m_inline_style && m_inline_style->is_updating())
return;
if (!m_inline_style)
m_inline_style = CSS::CSSStyleProperties::create_element_inline_style({ *this }, {}, {});
m_inline_style->set_declarations_from_text(*value);
set_needs_style_update(true);
}
// https://drafts.csswg.org/cssom/#ref-for-cssstyledeclaration-updating-flag
if (m_inline_style && m_inline_style->is_updating())
return;
if (!m_inline_style)
m_inline_style = CSS::CSSStyleProperties::create_element_inline_style({ *this }, {}, {});
m_inline_style->set_declarations_from_text(value.value_or(""_string));
set_needs_style_update(true);
} else if (local_name == HTML::AttributeNames::dir) {
// https://html.spec.whatwg.org/multipage/dom.html#attr-dir
if (value_or_empty.equals_ignoring_ascii_case("ltr"sv))