From 7c78d5b8d2b5abec8a2f4ee79f7b30348d5ebe8b Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Emilio=20Cobos=20=C3=81lvarez?= Date: Wed, 22 Jul 2026 21:06:19 +0000 Subject: [PATCH] Bug 2056795 - Don't start deferred loads immediately if aren't supposed to. r=layout-reviewers,firefox-style-system-reviewers,dshin Differential Revision: https://phabricator.services.mozilla.com/D313580 --- layout/style/Loader.cpp | 13 ++-- layout/style/SharedStyleSheetCache.cpp | 17 +++-- ...-alt.html => link-load-event-alt-001.html} | 0 .../link-load-event-alt-002.html | 63 +++++++++++++++++++ 4 files changed, 84 insertions(+), 9 deletions(-) rename testing/web-platform/tests/html/semantics/document-metadata/the-link-element/{link-load-event-alt.html => link-load-event-alt-001.html} (100%) create mode 100644 testing/web-platform/tests/html/semantics/document-metadata/the-link-element/link-load-event-alt-002.html diff --git a/layout/style/Loader.cpp b/layout/style/Loader.cpp index 4fd35e50ec73..b90a85948b4a 100644 --- a/layout/style/Loader.cpp +++ b/layout/style/Loader.cpp @@ -1573,14 +1573,19 @@ void Loader::NotifyObservers(SheetLoadData& aData, nsresult aStatus, RefPtr loadDispatcher = aData.PrepareLoadEventIfNeeded(); if (aData.mURI) { aData.NotifyStop(aStatus); - // NOTE(emilio): This needs to happen before notifying observers, as - // FontFaceSet for example checks for pending sheet loads from the - // StyleSheetLoaded callback. + // NOTE(emilio): DecrementOngoingLoadCountAndMaybeUnblockOnload() needs to + // happen before notifying observers, as FontFaceSet for example checks for + // pending sheet loads from the StyleSheetLoaded callback. if (aData.BlocksLoadEvent()) { DecrementOngoingLoadCountAndMaybeUnblockOnload(); if (mPendingLoadCount && mPendingLoadCount == mOngoingLoadCount) { LOG((" No more loading sheets; starting deferred loads")); - StartDeferredLoads(); + if (aCanFireEvents) { + StartDeferredLoads(); + } else { + NS_DispatchToMainThread(NewRunnableMethod( + "Loader::StartDeferredLoads", this, &Loader::StartDeferredLoads)); + } } } } diff --git a/layout/style/SharedStyleSheetCache.cpp b/layout/style/SharedStyleSheetCache.cpp index 672179455058..cdef942f7af1 100644 --- a/layout/style/SharedStyleSheetCache.cpp +++ b/layout/style/SharedStyleSheetCache.cpp @@ -58,11 +58,18 @@ void SharedStyleSheetCache::LoadCompleted(SharedStyleSheetCache* aCache, } while ((data = data->mNext)); } - // The only way of getting a load with mMustNotify = false before one with - // mMustNotify = true should be when we try to kick off a deferred load from a - // non-deferred one, and the load fails right away. In that case, it's not - // sound to try to fire events synchronously. - const bool canFireEvents = aData.mMustNotify; + // The only way of getting a load with mMustNotify = false before or inside + // one with mMustNotify = true should be when we try to kick off a deferred + // load from a non-deferred one, and the load fails right away. In that case, + // it's not sound to try to fire events synchronously. + const bool canFireEvents = [&] { + for (auto* data = &aData; data; data = data->mParentData) { + if (!data->mMustNotify) { + return false; + } + } + return true; + }(); // 8 is probably big enough for all our common cases. It's not likely that // imports will nest more than 8 deep, and multiple sheets with the same URI diff --git a/testing/web-platform/tests/html/semantics/document-metadata/the-link-element/link-load-event-alt.html b/testing/web-platform/tests/html/semantics/document-metadata/the-link-element/link-load-event-alt-001.html similarity index 100% rename from testing/web-platform/tests/html/semantics/document-metadata/the-link-element/link-load-event-alt.html rename to testing/web-platform/tests/html/semantics/document-metadata/the-link-element/link-load-event-alt-001.html diff --git a/testing/web-platform/tests/html/semantics/document-metadata/the-link-element/link-load-event-alt-002.html b/testing/web-platform/tests/html/semantics/document-metadata/the-link-element/link-load-event-alt-002.html new file mode 100644 index 000000000000..155cc3c918ae --- /dev/null +++ b/testing/web-platform/tests/html/semantics/document-metadata/the-link-element/link-load-event-alt-002.html @@ -0,0 +1,63 @@ + + + + + +