Skip to content

Truly independent web browser

LibWeb: Share one fetch per external document between use elements

Andreas Kling821dd311f3b8
diff --git a/Libraries/LibWeb/SVG/SVGUseElement.cpp b/Libraries/LibWeb/SVG/SVGUseElement.cpp
index ddadbe50f69..e23a182d40d 100644
--- a/Libraries/LibWeb/SVG/SVGUseElement.cpp
+++ b/Libraries/LibWeb/SVG/SVGUseElement.cpp
@@ -278,8 +278,14 @@ void SVGUseElement::fetch_the_document(URL::URL const& url)
if (document().is_temporary_document_for_fragment_parsing())
return;
+ // NB: The fragment only identifies the target element within the fetched document, so every reference to the same
+ // external document shares one fetch and one parsed document. The spec allows this re-use under "Processing
+ // the subresource document".
+ auto document_url = url;
+ document_url.set_fragment({});
+
m_load_event_delayer.emplace(document());
- m_resource_request = HTML::SharedResourceRequest::get_or_create(document(), url, HTML::CORSSettingAttribute::NoCORS);
+ m_resource_request = HTML::SharedResourceRequest::get_or_create(document(), document_url, HTML::CORSSettingAttribute::NoCORS);
m_resource_request->add_callbacks(
[this] {
clone_element_tree_as_our_shadow_tree(referenced_element());
@@ -293,7 +299,7 @@ void SVGUseElement::fetch_the_document(URL::URL const& url)
});
if (m_resource_request->needs_fetching()) {
- auto request = HTML::create_potential_CORS_request(url, Fetch::Infrastructure::Request::Destination::Image, HTML::CORSSettingAttribute::NoCORS);
+ auto request = HTML::create_potential_CORS_request(document_url, Fetch::Infrastructure::Request::Destination::Image, HTML::CORSSettingAttribute::NoCORS);
request->set_client(document().relevant_settings_object().address());
m_resource_request->fetch_resource(request);
}
diff --git a/Tests/LibWeb/Text/expected/SVG/use-element-external-fragments-share-one-fetch.txt b/Tests/LibWeb/Text/expected/SVG/use-element-external-fragments-share-one-fetch.txt
index 7b302d3a972..ef3c1d74e6a 100644
--- a/Tests/LibWeb/Text/expected/SVG/use-element-external-fragments-share-one-fetch.txt
+++ b/Tests/LibWeb/Text/expected/SVG/use-element-external-fragments-share-one-fetch.txt
@@ -1,4 +1,4 @@
-Requests for the sprite: 3
+Requests for the sprite: 1
useFirst: first-rect
useSecond: second-circle
useThird: third-path