LibWeb: Don't delay document load event forever with cached style sheets

If we try to <link> a stylesheet that was already cached, we'll get a
synchronous resource_did_load() callback. Because of this, it's
necessary to set up the document load event delayer *before* calling
set_resource(), as otherwise we'd be stuck without a load event forever.
This commit is contained in:
Andreas Kling 2022-02-15 14:11:51 +01:00
parent 9f02afd8fe
commit 32b8023ad1
Notes: sideshowbarker 2024-07-17 18:45:51 +09:00

View File

@ -33,8 +33,10 @@ void HTMLLinkElement::inserted()
auto url = document().parse_url(href());
dbgln_if(CSS_LOADER_DEBUG, "HTMLLinkElement: Loading import URL: {}", url);
auto request = LoadRequest::create_for_url_on_page(url, document().page());
set_resource(ResourceLoader::the().load_resource(Resource::Type::Generic, request));
// NOTE: Mark this element as delaying the document load event *before* calling set_resource()
// as it may trigger a synchronous resource_did_load() callback.
m_document_load_event_delayer.emplace(document());
set_resource(ResourceLoader::the().load_resource(Resource::Type::Generic, request));
}
if (m_relationship & Relationship::Preload) {