mirror of
https://github.com/LadybirdBrowser/ladybird.git
synced 2025-06-11 18:20:43 +09:00
LibWeb: Only reload link on rel change if it became a stylesheet
This commit is contained in:
parent
cd576e594d
commit
bf36d829ef
Notes:
github-actions[bot]
2025-01-20 17:22:22 +00:00
Author: https://github.com/Gingeh
Commit: bf36d829ef
Pull-request: https://github.com/LadybirdBrowser/ladybird/pull/3316
Reviewed-by: https://github.com/tcl3
3 changed files with 24 additions and 2 deletions
|
@ -124,6 +124,7 @@ void HTMLLinkElement::attribute_changed(FlyString const& name, Optional<String>
|
||||||
Base::attribute_changed(name, old_value, value, namespace_);
|
Base::attribute_changed(name, old_value, value, namespace_);
|
||||||
|
|
||||||
// 4.6.7 Link types - https://html.spec.whatwg.org/multipage/links.html#linkTypes
|
// 4.6.7 Link types - https://html.spec.whatwg.org/multipage/links.html#linkTypes
|
||||||
|
auto old_relationship = m_relationship;
|
||||||
if (name == HTML::AttributeNames::rel) {
|
if (name == HTML::AttributeNames::rel) {
|
||||||
m_relationship = 0;
|
m_relationship = 0;
|
||||||
// Keywords are always ASCII case-insensitive, and must be compared as such.
|
// Keywords are always ASCII case-insensitive, and must be compared as such.
|
||||||
|
@ -165,8 +166,8 @@ void HTMLLinkElement::attribute_changed(FlyString const& name, Optional<String>
|
||||||
if (
|
if (
|
||||||
is_browsing_context_connected()
|
is_browsing_context_connected()
|
||||||
&& (
|
&& (
|
||||||
// AD-HOC: When the rel attribute changes
|
// AD-HOC: When the link element's type becomes a stylesheet
|
||||||
name == AttributeNames::rel ||
|
!(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.
|
// - When the href attribute of the link element of an external resource link that is already browsing-context connected is changed.
|
||||||
name == AttributeNames::href ||
|
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.
|
// - When the disabled attribute of the link element of an external resource link that is already browsing-context connected is set, changed, or removed.
|
||||||
|
|
1
Tests/LibWeb/Text/expected/link-changed-rel.txt
Normal file
1
Tests/LibWeb/Text/expected/link-changed-rel.txt
Normal file
|
@ -0,0 +1 @@
|
||||||
|
Got load event
|
20
Tests/LibWeb/Text/input/link-changed-rel.html
Normal file
20
Tests/LibWeb/Text/input/link-changed-rel.html
Normal file
|
@ -0,0 +1,20 @@
|
||||||
|
<!DOCTYPE html>
|
||||||
|
<script src="include.js"></script>
|
||||||
|
<script>
|
||||||
|
asyncTest(done => {
|
||||||
|
let link = document.createElement("link");
|
||||||
|
link.setAttribute("href", "valid.css");
|
||||||
|
link.addEventListener("load", function() {
|
||||||
|
println("Got load event");
|
||||||
|
|
||||||
|
// link is still a stylesheet (no event)
|
||||||
|
link.setAttribute("rel", "preconnect stylesheet");
|
||||||
|
});
|
||||||
|
document.head.appendChild(link);
|
||||||
|
|
||||||
|
// link becomes a stylesheet (event)
|
||||||
|
link.setAttribute("rel", "stylesheet");
|
||||||
|
|
||||||
|
setTimeout(done, 1000);
|
||||||
|
});
|
||||||
|
</script>
|
Loading…
Add table
Add a link
Reference in a new issue