diff --git a/Tests/LibWeb/Text/expected/css/custom-properties-from-all-layers.txt b/Tests/LibWeb/Text/expected/css/custom-properties-from-all-layers.txt
new file mode 100644
index 00000000000..8b6f94330d6
--- /dev/null
+++ b/Tests/LibWeb/Text/expected/css/custom-properties-from-all-layers.txt
@@ -0,0 +1,4 @@
+ 1px
+2px
+3px
+4px
diff --git a/Tests/LibWeb/Text/input/css/custom-properties-from-all-layers.html b/Tests/LibWeb/Text/input/css/custom-properties-from-all-layers.html
new file mode 100644
index 00000000000..c8251a21e0c
--- /dev/null
+++ b/Tests/LibWeb/Text/input/css/custom-properties-from-all-layers.html
@@ -0,0 +1,23 @@
+
+
+
diff --git a/Userland/Libraries/LibWeb/CSS/StyleComputer.cpp b/Userland/Libraries/LibWeb/CSS/StyleComputer.cpp
index 83d27dee5df..543aeb80c3b 100644
--- a/Userland/Libraries/LibWeb/CSS/StyleComputer.cpp
+++ b/Userland/Libraries/LibWeb/CSS/StyleComputer.cpp
@@ -961,7 +961,7 @@ void StyleComputer::cascade_declarations(StyleProperties& style, DOM::Element& e
}
}
-static void cascade_custom_properties(DOM::Element& element, Optional pseudo_element, Vector const& matching_rules)
+static void cascade_custom_properties(DOM::Element& element, Optional pseudo_element, Vector const& matching_rules, HashMap& custom_properties)
{
size_t needed_capacity = 0;
for (auto const& matching_rule : matching_rules)
@@ -972,8 +972,7 @@ static void cascade_custom_properties(DOM::Element& element, Optionalcustom_properties().size();
}
- HashMap custom_properties;
- custom_properties.ensure_capacity(needed_capacity);
+ custom_properties.ensure_capacity(custom_properties.size() + needed_capacity);
for (auto const& matching_rule : matching_rules) {
for (auto const& it : matching_rule.rule->declaration().custom_properties())
@@ -986,8 +985,6 @@ static void cascade_custom_properties(DOM::Element& element, Optional interpolate_value(DOM::Element& element, CSSStyleValue const& from, CSSStyleValue const& to, float delta);
@@ -1778,9 +1775,12 @@ void StyleComputer::compute_cascaded_values(StyleProperties& style, DOM::Element
// Then we resolve all the CSS custom properties ("variables") for this element:
// FIXME: Also resolve !important custom properties, in a second cascade.
+
+ HashMap custom_properties;
for (auto& layer : matching_rule_set.author_rules) {
- cascade_custom_properties(element, pseudo_element, layer.rules);
+ cascade_custom_properties(element, pseudo_element, layer.rules, custom_properties);
}
+ element.set_custom_properties(pseudo_element, move(custom_properties));
// Then we apply the declarations from the matched rules in cascade order: