Skip to content

Truly independent web browser

LibWeb: Skip cached unregistered property keyframes in cycle detection

Callum Lawfc4ca9eb5525
diff --git a/Libraries/LibWeb/Rust/src/css/animation.rs b/Libraries/LibWeb/Rust/src/css/animation.rs
index 55cea58aa43..9cd2b99c65b 100644
--- a/Libraries/LibWeb/Rust/src/css/animation.rs
+++ b/Libraries/LibWeb/Rust/src/css/animation.rs
@@ -8623,6 +8623,7 @@ pub(crate) struct CustomPropertyInterval {
pub(crate) custom_name_id: u32,
pub(crate) cyclic: [bool; 2],
pub(crate) name: crate::css::retained_fly_string::RetainedUtf16FlyString,
+ /// Written endpoint values; empty for neutral endpoints and for cached unregistered intervals.
pub(crate) declared_values: [RetainedStyleValueData; 2],
/// Fresh interval values awaiting cache insertion.
pub(crate) values_to_retain: Option<[RetainedStyleValueData; 2]>,
@@ -9162,6 +9163,9 @@ pub(crate) fn resolve_published_animation_declarations(
let custom_is_inherited = registry.name_inherits(&interned_name);
interval.values_to_retain =
(can_retain_interval_values && !has_retained_values).then(|| interval_values.clone());
+ if has_retained_values && !registry.is_registered(&interned_name) {
+ interval.declared_values.fill(RetainedStyleValueData::none());
+ }
for (lookup, value) in interval.interval_span.into_iter().zip(interval_values) {
let declaration = effect.custom_declaration_at(lookup.declaration_index);
declarations.push(AnimationDeclaration {
diff --git a/Libraries/LibWeb/Rust/src/css/style/custom_property_cascade.rs b/Libraries/LibWeb/Rust/src/css/style/custom_property_cascade.rs
index 9bb724dc354..e43bf41c2d8 100644
--- a/Libraries/LibWeb/Rust/src/css/style/custom_property_cascade.rs
+++ b/Libraries/LibWeb/Rust/src/css/style/custom_property_cascade.rs
@@ -827,7 +827,8 @@ impl RetainedState {
/// Mark cyclic endpoints in `intervals` and return the names of cyclic element declarations.
/// Cycles can pass through the selected animation intervals, as with
/// `--p: var(--q)` in a keyframe beside `--q: var(--p)` on the element. An animated value wins
- /// the cascade over a declared one, so a name it animates reads as its selected endpoints do. What a value
+ /// the cascade over a declared one. Retained unregistered intervals shadow declarations without
+ /// adding dependencies; other intervals read as their selected endpoints do. What a value
/// reads is what substituting it looks up, over `base`, the element's environment beneath its
/// animations, with their values `animated`, and `inheritance`, the environment it inherits:
/// which branch of an `if()` or fallback that takes depends on the values, and what decides that
diff --git a/Libraries/LibWeb/Rust/src/css/style/effect_descriptions.rs b/Libraries/LibWeb/Rust/src/css/style/effect_descriptions.rs
index 7027edafaf7..80c5a5796d4 100644
--- a/Libraries/LibWeb/Rust/src/css/style/effect_descriptions.rs
+++ b/Libraries/LibWeb/Rust/src/css/style/effect_descriptions.rs
@@ -473,10 +473,19 @@ impl PublishedEffect {
return;
}
- let Some(values) = interval.values_to_retain else {
+ let Some(mut values) = interval.values_to_retain else {
return;
};
+ for (value, cyclic) in values.iter_mut().zip(interval.cyclic) {
+ if !cyclic {
+ continue;
+ }
+ // AD-HOC: Retain a cyclic conversion as unset so its inherited or initial value is resolved when applied.
+ // Caching the fallback's value would freeze it across later style changes.
+ *value = RetainedStyleValueData::shared_keyword(crate::css::css_enums::keyword::UNSET).clone();
+ }
+
interval_cache
.lock()
.unwrap()
diff --git a/Tests/LibWeb/Text/expected/css/unregistered-custom-property-animation-cycle-retained.txt b/Tests/LibWeb/Text/expected/css/unregistered-custom-property-animation-cycle-retained.txt
new file mode 100644
index 00000000000..fe5a9da0ef6
--- /dev/null
+++ b/Tests/LibWeb/Text/expected/css/unregistered-custom-property-animation-cycle-retained.txt
@@ -0,0 +1,3 @@
+retained values do not recreate a dependency cycle: true
+cyclic conversions inherit the parent's value: true
+inherited values remain live when the parent changes: true
diff --git a/Tests/LibWeb/Text/input/css/unregistered-custom-property-animation-cycle-retained.html b/Tests/LibWeb/Text/input/css/unregistered-custom-property-animation-cycle-retained.html
new file mode 100644
index 00000000000..9abd6905f7f
--- /dev/null
+++ b/Tests/LibWeb/Text/input/css/unregistered-custom-property-animation-cycle-retained.html
@@ -0,0 +1,47 @@
+<!doctype html>
+<style>
+ @property --value {
+ syntax: "<integer>";
+ inherits: true;
+ initial-value: 0;
+ }
+ @keyframes capture {
+ from,
+ to {
+ --saved: var(--value);
+ }
+ }
+ .target {
+ --value: calc(var(--saved, 0) + 1);
+ animation: capture 1s paused;
+ }
+</style>
+<div id="target" class="target"></div>
+<div id="parent" style="--saved: 7"><div id="inherited" class="target"></div></div>
+<script src="../include.js"></script>
+<script>
+ test(() => {
+ const target = document.getElementById("target");
+ const inherited = document.getElementById("inherited");
+ const parent = document.getElementById("parent");
+ const value = element => getComputedStyle(element).getPropertyValue("--value");
+ // NB: Resolve the initial animation samples before testing retained values after style changes.
+ value(target);
+ value(inherited);
+
+ target.style.color = "red";
+ println(`retained values do not recreate a dependency cycle: ${value(target) === "1"}`);
+
+ const inheritsSavedValue = expected => {
+ const style = getComputedStyle(inherited);
+ return (
+ style.getPropertyValue("--saved") === String(expected) &&
+ style.getPropertyValue("--value") === String(expected + 1)
+ );
+ };
+ inherited.style.color = "red";
+ println(`cyclic conversions inherit the parent's value: ${inheritsSavedValue(7)}`);
+ parent.style.setProperty("--saved", "9");
+ println(`inherited values remain live when the parent changes: ${inheritsSavedValue(9)}`);
+ });
+</script>