diff --git a/Userland/Libraries/LibWeb/DOM/Document.h b/Userland/Libraries/LibWeb/DOM/Document.h index fc4e0bf352e..2c7eb1a7449 100644 --- a/Userland/Libraries/LibWeb/DOM/Document.h +++ b/Userland/Libraries/LibWeb/DOM/Document.h @@ -97,6 +97,11 @@ public: static WebIDL::ExceptionOr> construct_impl(JS::Realm&); virtual ~Document() override; + // AD-HOC: This number increments whenever a node is added or removed from the document, or an element attribute changes. + // It can be used as a crude invalidation mechanism for caches that depend on the DOM structure. + u64 dom_tree_version() const { return m_dom_tree_version; } + void bump_dom_tree_version() { ++m_dom_tree_version; } + WebIDL::ExceptionOr populate_with_html_head_and_body(); JS::GCPtr get_selection() const; @@ -846,6 +851,8 @@ private: mutable JS::GCPtr m_adopted_style_sheets; Vector> m_shadow_roots; + + u64 m_dom_tree_version { 0 }; }; template<> diff --git a/Userland/Libraries/LibWeb/DOM/Element.cpp b/Userland/Libraries/LibWeb/DOM/Element.cpp index 2c19e694bb5..2b150fcf30d 100644 --- a/Userland/Libraries/LibWeb/DOM/Element.cpp +++ b/Userland/Libraries/LibWeb/DOM/Element.cpp @@ -437,6 +437,8 @@ void Element::run_attribute_change_steps(FlyString const& local_name, Optional const& value) diff --git a/Userland/Libraries/LibWeb/DOM/Node.cpp b/Userland/Libraries/LibWeb/DOM/Node.cpp index 7a4c896f5f5..f7b89a9a1d6 100644 --- a/Userland/Libraries/LibWeb/DOM/Node.cpp +++ b/Userland/Libraries/LibWeb/DOM/Node.cpp @@ -207,6 +207,8 @@ void Node::set_text_content(Optional const& maybe_content) document().invalidate_style(); document().invalidate_layout(); + + document().bump_dom_tree_version(); } // https://dom.spec.whatwg.org/#dom-node-nodevalue @@ -510,6 +512,8 @@ void Node::insert_before(JS::NonnullGCPtr node, JS::GCPtr child, boo invalidate_style(); document().invalidate_layout(); + + document().bump_dom_tree_version(); } // https://dom.spec.whatwg.org/#concept-node-pre-insert @@ -703,6 +707,8 @@ void Node::remove(bool suppress_observers) // In the future, we should find a way to only invalidate the parts that actually need it. document().invalidate_style(); document().invalidate_layout(); + + document().bump_dom_tree_version(); } // https://dom.spec.whatwg.org/#concept-node-replace