From 84c4eb7aa9353a3ad77b10b27b2bc9ef6af2b1ec Mon Sep 17 00:00:00 2001 From: Jelle Raaijmakers Date: Tue, 26 Aug 2025 14:23:30 +0200 Subject: [PATCH] LibWeb: Always update computed properties for finished animations If an animation got to its finished state before its target's computed properties could be updated, we would end up with invalid styles. Do not skip finished animations, but prevent effect invalidation on timeline updates if the animation is already finished. This fixes the CI flake on WPT test `css/css-transitions/inherit-height-transition.html`. --- Libraries/LibWeb/Animations/Animation.cpp | 11 ++++++----- Libraries/LibWeb/DOM/Document.cpp | 5 ++--- .../css/css-transitions/transitioncancel-003.txt | 4 ++-- 3 files changed, 10 insertions(+), 10 deletions(-) diff --git a/Libraries/LibWeb/Animations/Animation.cpp b/Libraries/LibWeb/Animations/Animation.cpp index 8f69d371c93..75caac5b52e 100644 --- a/Libraries/LibWeb/Animations/Animation.cpp +++ b/Libraries/LibWeb/Animations/Animation.cpp @@ -1,5 +1,6 @@ /* * Copyright (c) 2023-2024, Matthew Olsson . + * Copyright (c) 2025, Jelle Raaijmakers * * SPDX-License-Identifier: BSD-2-Clause */ @@ -934,7 +935,9 @@ GC::Ptr Animation::document_for_timing() const void Animation::notify_timeline_time_did_change() { - update_finished_state(DidSeek::No, SynchronouslyNotify::Yes); + // Update finished state if not already finished; prevents recurring invalidation when the timeline updates. + if (!m_is_finished) + update_finished_state(DidSeek::No, SynchronouslyNotify::Yes); // Act on the pending play or pause task if (m_pending_play_task == TaskState::Scheduled) { @@ -1330,13 +1333,11 @@ GC::Ref Animation::current_finished_promise() const void Animation::invalidate_effect() { - if (!m_effect) { + if (!m_effect) return; - } - if (auto* target = m_effect->target(); target) { + if (auto* target = m_effect->target()) target->document().set_needs_animated_style_update(); - } } Animation::Animation(JS::Realm& realm) diff --git a/Libraries/LibWeb/DOM/Document.cpp b/Libraries/LibWeb/DOM/Document.cpp index f02077a11d8..d9d6ec2a425 100644 --- a/Libraries/LibWeb/DOM/Document.cpp +++ b/Libraries/LibWeb/DOM/Document.cpp @@ -1574,11 +1574,10 @@ void Document::update_animated_style_if_needed() for (auto& timeline : m_associated_animation_timelines) { for (auto& animation : timeline->associated_animations()) { - if (animation->is_idle() || animation->is_finished()) + if (animation->is_idle()) continue; - if (auto effect = animation->effect()) { + if (auto effect = animation->effect()) effect->update_computed_properties(context); - } } } diff --git a/Tests/LibWeb/Text/expected/wpt-import/css/css-transitions/transitioncancel-003.txt b/Tests/LibWeb/Text/expected/wpt-import/css/css-transitions/transitioncancel-003.txt index 93cbe377682..cbb9ab615dd 100644 --- a/Tests/LibWeb/Text/expected/wpt-import/css/css-transitions/transitioncancel-003.txt +++ b/Tests/LibWeb/Text/expected/wpt-import/css/css-transitions/transitioncancel-003.txt @@ -2,5 +2,5 @@ Harness status: OK Found 1 tests -1 Fail -Fail Mid-transition transition changes affect subsequent transitions \ No newline at end of file +1 Pass +Pass Mid-transition transition changes affect subsequent transitions \ No newline at end of file