diff --git a/Libraries/LibWeb/CSS/StyleInvalidator.cpp b/Libraries/LibWeb/CSS/StyleInvalidator.cpp index 0dd48840d51..bf5f15c332f 100644 --- a/Libraries/LibWeb/CSS/StyleInvalidator.cpp +++ b/Libraries/LibWeb/CSS/StyleInvalidator.cpp @@ -33,6 +33,8 @@ namespace Web::CSS { StyleInvalidator::StyleInvalidator(DOM::Document& document) : m_document(document) { + if (!m_document.should_invalidate_styles_on_attribute_changes()) + return; auto& style_resolver = m_document.style_resolver(); m_document.for_each_in_subtree_of_type([&](auto& element) { m_elements_and_matching_rules_before.set(&element, style_resolver.collect_matching_rules(element)); @@ -42,6 +44,8 @@ StyleInvalidator::StyleInvalidator(DOM::Document& document) StyleInvalidator::~StyleInvalidator() { + if (!m_document.should_invalidate_styles_on_attribute_changes()) + return; auto& style_resolver = m_document.style_resolver(); m_document.for_each_in_subtree_of_type([&](auto& element) { auto maybe_matching_rules_before = m_elements_and_matching_rules_before.get(&element); diff --git a/Libraries/LibWeb/DOM/Document.h b/Libraries/LibWeb/DOM/Document.h index 0dba6aed7b4..8434beeb8ef 100644 --- a/Libraries/LibWeb/DOM/Document.h +++ b/Libraries/LibWeb/DOM/Document.h @@ -61,6 +61,9 @@ public: static NonnullRefPtr create(const URL& url = "about:blank") { return adopt(*new Document(url)); } virtual ~Document() override; + bool should_invalidate_styles_on_attribute_changes() const { return m_should_invalidate_styles_on_attribute_changes; } + void set_should_invalidate_styles_on_attribute_changes(bool b) { m_should_invalidate_styles_on_attribute_changes = b; } + void set_url(const URL& url) { m_url = url; } URL url() const { return m_url; } @@ -283,6 +286,8 @@ private: bool m_ready_for_post_load_tasks { false }; NonnullRefPtr m_implementation; + + bool m_should_invalidate_styles_on_attribute_changes { true }; }; } diff --git a/Libraries/LibWeb/HTML/Parser/HTMLDocumentParser.cpp b/Libraries/LibWeb/HTML/Parser/HTMLDocumentParser.cpp index 1927274a73d..417effea759 100644 --- a/Libraries/LibWeb/HTML/Parser/HTMLDocumentParser.cpp +++ b/Libraries/LibWeb/HTML/Parser/HTMLDocumentParser.cpp @@ -122,11 +122,13 @@ HTMLDocumentParser::HTMLDocumentParser(DOM::Document& document, const StringView : m_tokenizer(input, encoding) , m_document(document) { + m_document->set_should_invalidate_styles_on_attribute_changes(false); m_document->set_encoding(TextCodec::get_standardized_encoding(encoding)); } HTMLDocumentParser::~HTMLDocumentParser() { + m_document->set_should_invalidate_styles_on_attribute_changes(true); } void HTMLDocumentParser::run(const URL& url)