From bf36d829ef9259fabdfd8f31771b1b398ec37ac0 Mon Sep 17 00:00:00 2001 From: Gingeh <39150378+Gingeh@users.noreply.github.com> Date: Mon, 20 Jan 2025 16:26:59 +1100 Subject: [PATCH] LibWeb: Only reload link on rel change if it became a stylesheet --- Libraries/LibWeb/HTML/HTMLLinkElement.cpp | 5 +++-- .../LibWeb/Text/expected/link-changed-rel.txt | 1 + Tests/LibWeb/Text/input/link-changed-rel.html | 20 +++++++++++++++++++ 3 files changed, 24 insertions(+), 2 deletions(-) create mode 100644 Tests/LibWeb/Text/expected/link-changed-rel.txt create mode 100644 Tests/LibWeb/Text/input/link-changed-rel.html diff --git a/Libraries/LibWeb/HTML/HTMLLinkElement.cpp b/Libraries/LibWeb/HTML/HTMLLinkElement.cpp index f4aa0b7c48c..333776d5ff0 100644 --- a/Libraries/LibWeb/HTML/HTMLLinkElement.cpp +++ b/Libraries/LibWeb/HTML/HTMLLinkElement.cpp @@ -124,6 +124,7 @@ void HTMLLinkElement::attribute_changed(FlyString const& name, Optional Base::attribute_changed(name, old_value, value, namespace_); // 4.6.7 Link types - https://html.spec.whatwg.org/multipage/links.html#linkTypes + auto old_relationship = m_relationship; if (name == HTML::AttributeNames::rel) { m_relationship = 0; // Keywords are always ASCII case-insensitive, and must be compared as such. @@ -165,8 +166,8 @@ void HTMLLinkElement::attribute_changed(FlyString const& name, Optional if ( is_browsing_context_connected() && ( - // AD-HOC: When the rel attribute changes - name == AttributeNames::rel || + // AD-HOC: When the link element's type becomes a stylesheet + !(old_relationship & Relationship::Stylesheet) || // - When the href attribute of the link element of an external resource link that is already browsing-context connected is changed. name == AttributeNames::href || // - When the disabled attribute of the link element of an external resource link that is already browsing-context connected is set, changed, or removed. diff --git a/Tests/LibWeb/Text/expected/link-changed-rel.txt b/Tests/LibWeb/Text/expected/link-changed-rel.txt new file mode 100644 index 00000000000..fd7ee7517ba --- /dev/null +++ b/Tests/LibWeb/Text/expected/link-changed-rel.txt @@ -0,0 +1 @@ +Got load event diff --git a/Tests/LibWeb/Text/input/link-changed-rel.html b/Tests/LibWeb/Text/input/link-changed-rel.html new file mode 100644 index 00000000000..61f32bc0ae0 --- /dev/null +++ b/Tests/LibWeb/Text/input/link-changed-rel.html @@ -0,0 +1,20 @@ + + +