From 57e26ed6b9b2c0cf1e4f5ac3e85ca0c7f3647caa Mon Sep 17 00:00:00 2001 From: Andreas Kling Date: Sun, 22 Sep 2024 13:29:49 +0200 Subject: [PATCH] LibWeb: Abort ongoing fetch before starting a new link element fetch If we decide to fetch another linked resource, we don't care about the earlier fetch and can safely abort it. This fixes an issue on GitHub where we'd load the same style sheet multiple times and invalidate style for the entire document every time it finished fetching. By aborting the ongoing fetch, no excess invalidation happens. --- Userland/Libraries/LibWeb/HTML/HTMLLinkElement.cpp | 6 +++++- Userland/Libraries/LibWeb/HTML/HTMLLinkElement.h | 2 ++ 2 files changed, 7 insertions(+), 1 deletion(-) diff --git a/Userland/Libraries/LibWeb/HTML/HTMLLinkElement.cpp b/Userland/Libraries/LibWeb/HTML/HTMLLinkElement.cpp index 3d998776c96..9512c217490 100644 --- a/Userland/Libraries/LibWeb/HTML/HTMLLinkElement.cpp +++ b/Userland/Libraries/LibWeb/HTML/HTMLLinkElement.cpp @@ -19,6 +19,7 @@ #include #include #include +#include #include #include #include @@ -364,7 +365,9 @@ void HTMLLinkElement::default_fetch_and_process_linked_resource() process_linked_resource(success, response, body_bytes); }; - Fetch::Fetching::fetch(realm(), *request, Fetch::Infrastructure::FetchAlgorithms::create(vm(), move(fetch_algorithms_input))).release_value_but_fixme_should_propagate_errors(); + if (m_fetch_controller) + m_fetch_controller->abort(realm(), {}); + m_fetch_controller = MUST(Fetch::Fetching::fetch(realm(), *request, Fetch::Infrastructure::FetchAlgorithms::create(vm(), move(fetch_algorithms_input)))); } // https://html.spec.whatwg.org/multipage/links.html#link-type-stylesheet:process-the-linked-resource @@ -610,6 +613,7 @@ WebIDL::ExceptionOr HTMLLinkElement::load_fallback_favicon_if_needed(JS::N void HTMLLinkElement::visit_edges(Cell::Visitor& visitor) { Base::visit_edges(visitor); + visitor.visit(m_fetch_controller); visitor.visit(m_loaded_style_sheet); visitor.visit(m_rel_list); } diff --git a/Userland/Libraries/LibWeb/HTML/HTMLLinkElement.h b/Userland/Libraries/LibWeb/HTML/HTMLLinkElement.h index b2c50a1625d..0b6d69f3869 100644 --- a/Userland/Libraries/LibWeb/HTML/HTMLLinkElement.h +++ b/Userland/Libraries/LibWeb/HTML/HTMLLinkElement.h @@ -140,6 +140,8 @@ private: }; }; + JS::GCPtr m_fetch_controller; + JS::GCPtr m_loaded_style_sheet; Optional m_document_load_event_delayer;