diff --git a/Libraries/LibWeb/CSS/StyleSheetList.cpp b/Libraries/LibWeb/CSS/StyleSheetList.cpp index bd25d75bd87..6cc06989cd9 100644 --- a/Libraries/LibWeb/CSS/StyleSheetList.cpp +++ b/Libraries/LibWeb/CSS/StyleSheetList.cpp @@ -1,5 +1,5 @@ /* - * Copyright (c) 2020-2024, Andreas Kling + * Copyright (c) 2020-2025, Andreas Kling * Copyright (c) 2025, Sam Atkins * * SPDX-License-Identifier: BSD-2-Clause @@ -10,6 +10,7 @@ #include #include #include +#include namespace Web::CSS { @@ -108,6 +109,11 @@ void StyleSheetList::add_sheet(CSSStyleSheet& sheet) m_sheets.prepend(sheet); } + // NOTE: We evaluate media queries immediately when adding a new sheet. + // This coalesces the full document style invalidations. + // If we don't do this, we invalidate now, and then again when Document updates media rules. + sheet.evaluate_media_queries(as(HTML::relevant_global_object(*this))); + if (sheet.rules().length() == 0) { // NOTE: If the added sheet has no rules, we don't have to invalidate anything. return;