From 32b8023ad11434d9e8039cec07b77dcb6ad35913 Mon Sep 17 00:00:00 2001 From: Andreas Kling Date: Tue, 15 Feb 2022 14:11:51 +0100 Subject: LibWeb: Don't delay document load event forever with cached style sheets If we try to 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. --- Userland/Libraries/LibWeb/HTML/HTMLLinkElement.cpp | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) (limited to 'Userland/Libraries/LibWeb/HTML') diff --git a/Userland/Libraries/LibWeb/HTML/HTMLLinkElement.cpp b/Userland/Libraries/LibWeb/HTML/HTMLLinkElement.cpp index a67989527d..57518c3a87 100644 --- a/Userland/Libraries/LibWeb/HTML/HTMLLinkElement.cpp +++ b/Userland/Libraries/LibWeb/HTML/HTMLLinkElement.cpp @@ -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) { -- cgit v1.2.3