Truly independent web browser
LibWeb: Discard cached values for cyclic registered property intervals
Callum Lawa01ad0ff37d5
diff --git a/Libraries/LibWeb/Rust/src/css/style/effect_descriptions.rs b/Libraries/LibWeb/Rust/src/css/style/effect_descriptions.rsindex c53b8c4ed52..7027edafaf7 100644--- a/Libraries/LibWeb/Rust/src/css/style/effect_descriptions.rs+++ b/Libraries/LibWeb/Rust/src/css/style/effect_descriptions.rs@@ -448,17 +448,36 @@ impl PublishedEffect {(values, true)}- /// Retain freshly resolved values for an interval.- pub(crate) fn update_retained_custom_property_interval_values(&self, interval: CustomPropertyInterval) {+ /// Retain fresh interval values, or discard cached values for a cyclic registered interval.+ pub(crate) fn update_retained_custom_property_interval_values(+ &self,+ interval: CustomPropertyInterval,+ registry: &CustomPropertyRegistry,+ ) {let declaration_indices = interval.declaration_indices();+ let is_cyclic_registered_interval = interval.cyclic.contains(&true) && {+ // SAFETY: The interval retains the name while it is borrowed for the lookup.+ let name = unsafe { ak::Utf16FlyString::from_raw_borrowed(interval.name.raw()) };+ registry.is_registered(&name)+ };++ let interval_cache = self+ .custom_property_interval_values+ .as_ref()+ .expect("an effect interpolating custom properties keeps their interval values");++ // NB: Discard cached values for a cyclic registered interval so breaking the cycle converts its current declarations.+ if is_cyclic_registered_interval {+ interval_cache.lock().unwrap().remove(&declaration_indices);+ return;+ }+let Some(values) = interval.values_to_retain else {return;};- self.custom_property_interval_values- .as_ref()- .expect("an effect interpolating custom properties keeps their interval values")+ interval_cache.lock().unwrap().entry(declaration_indices)diff --git a/Libraries/LibWeb/Rust/src/css/style_compute.rs b/Libraries/LibWeb/Rust/src/css/style_compute.rsindex ca2ae10e487..05be2385918 100644--- a/Libraries/LibWeb/Rust/src/css/style_compute.rs+++ b/Libraries/LibWeb/Rust/src/css/style_compute.rs@@ -7380,6 +7380,7 @@ fn finish_animation_sample(engine.custom_property_registration_generation(),"animation sampling preserves custom property registrations");+ let registry = engine.custom_property_registry();let current_effects = described_effects(input, engine);for interval in custom_properties.intervals {let sampled_effect = composed[interval.effect_index].effect;@@ -7389,7 +7390,7 @@ fn finish_animation_sample(effect.identity == sampled_effect.identity && effect.generation == sampled_effect.generation}).expect("a sampled effect remains published with the same generation");- effect.update_retained_custom_property_interval_values(interval);+ effect.update_retained_custom_property_interval_values(interval, registry);}let rows = retained.iter()diff --git a/Tests/LibWeb/Text/expected/css/registered-custom-property-animation-cycle-recovery.txt b/Tests/LibWeb/Text/expected/css/registered-custom-property-animation-cycle-recovery.txtnew file mode 100644index 00000000000..9ab5ebe02a2--- /dev/null+++ b/Tests/LibWeb/Text/expected/css/registered-custom-property-animation-cycle-recovery.txt@@ -0,0 +1,8 @@+--ident restores its literal endpoint after breaking an initial cycle: safe+--ident refreshes its referenced keyframe value after breaking an initial cycle: changed+--ident uses its initial value after introducing a cycle: base+--ident refreshes its referenced keyframe value after introducing and breaking a cycle: changed+--universal restores its literal endpoint after breaking an initial cycle: safe+--universal refreshes its referenced keyframe value after breaking an initial cycle: changed+--universal uses its initial value after introducing a cycle: base+--universal refreshes its referenced keyframe value after introducing and breaking a cycle: changeddiff --git a/Tests/LibWeb/Text/input/css/registered-custom-property-animation-cycle-recovery.html b/Tests/LibWeb/Text/input/css/registered-custom-property-animation-cycle-recovery.htmlnew file mode 100644index 00000000000..823e92a3091--- /dev/null+++ b/Tests/LibWeb/Text/input/css/registered-custom-property-animation-cycle-recovery.html@@ -0,0 +1,76 @@+<!doctype html>+<style>+ @property --ident {+ syntax: "<custom-ident>";+ inherits: false;+ initial-value: base;+ }+ @property --universal {+ syntax: "*";+ inherits: false;+ initial-value: base;+ }+ @keyframes mixed {+ from {+ --ident: var(--ident-reader);+ --universal: var(--universal-reader);+ }+ 50%,+ to {+ --ident: safe;+ --universal: safe;+ }+ }+ .target {+ --ident-reader: base;+ --universal-reader: base;+ animation: mixed 1s linear paused;+ }+ #cyclic {+ --ident-reader: var(--ident);+ --universal-reader: var(--universal);+ }+</style>+<div id="cyclic" class="target"></div>+<div id="noncyclic" class="target"></div>+<script src="../include.js"></script>+<script>+ test(() => {+ const cyclic = document.getElementById("cyclic");+ const noncyclic = document.getElementById("noncyclic");+ const cyclicAnimation = cyclic.getAnimations()[0];+ const noncyclicAnimation = noncyclic.getAnimations()[0];+ cyclicAnimation.currentTime = 400;+ noncyclicAnimation.currentTime = 400;+ for (const name of ["--ident", "--universal"]) {+ const reader = `${name}-reader`;+ const value = target => getComputedStyle(target).getPropertyValue(name);+ // NB: Sample the referenced interval on both elements before changing whether it forms a cycle.+ value(cyclic);+ value(noncyclic);++ cyclic.style.setProperty(reader, "changed");+ // NB: Resolve the changed reader in the literal-only interval before sampling its referenced keyframe again.+ cyclicAnimation.currentTime = 900;+ value(cyclic);+ cyclicAnimation.currentTime = 400;+ println(`${name} restores its literal endpoint after breaking an initial cycle: ${value(cyclic)}`);+ cyclicAnimation.currentTime = 0;+ println(+ `${name} refreshes its referenced keyframe value after breaking an initial cycle: ${value(cyclic)}`+ );+ cyclicAnimation.currentTime = 400;++ noncyclic.style.setProperty(reader, `var(${name})`);+ println(`${name} uses its initial value after introducing a cycle: ${value(noncyclic)}`);+ noncyclic.style.setProperty(reader, "changed");+ noncyclicAnimation.currentTime = 900;+ value(noncyclic);+ noncyclicAnimation.currentTime = 0;+ println(+ `${name} refreshes its referenced keyframe value after introducing and breaking a cycle: ${value(noncyclic)}`+ );+ noncyclicAnimation.currentTime = 400;+ }+ });+</script>