From af1b0b0f14d951b8e712b71a220e308d7b2f0c2e Mon Sep 17 00:00:00 2001 From: yvt Date: Fri, 28 Oct 2022 12:49:47 +0900 Subject: [PATCH] fix(script): update animation timeline before processing pending events This commit reverses the order of the `send_pending_events` and `update_animation_timeline` calls in `ScriptThread::update_animations_ send_events` so that animation-related events pended by the latter are processed by the former. The new calling order is more compliant with the "update animations and send events" algorithm steps from [the Web Animations specification][1]. The old implementation was prone to blocking for an indefinite period while holding pending events. Due to complex interaction with other events and timing behavior, I was only able to reproduce the problem under the following conditions: - *The `maybe_observe_paint_time` call in `LayoutThread::compute_abs_ pos_and_build_display_list` is removed from the code*. While performance events may seem irrelevant to the issue, they would bombard the script thread with events. *Any* extra messages received would unblock the event loop and prevent the manifestation of the issue. (But, of course, we aren't supposed to count on that to avoid the issue.) - Servo is running in a headless mode, which somehow makes it less likely for the script thread to receive a `TickAllAnimations` event after sending `AnimationState::NoAnimationsPresent`. With the above conditions met and the stars aligned, you can reproduce the problem by running the WPT test `/css/css-transitions/events-001. html`. [1]: https://drafts.csswg.org/web-animations-1/#update-animations-and-send-events --- components/script/script_thread.rs | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/components/script/script_thread.rs b/components/script/script_thread.rs index 506cd5d6bf2..a82edd61cc3 100644 --- a/components/script/script_thread.rs +++ b/components/script/script_thread.rs @@ -1705,11 +1705,11 @@ impl ScriptThread { // Perform step 11.10 from https://html.spec.whatwg.org/multipage/#event-loops. fn update_animations_and_send_events(&self) { for (_, document) in self.documents.borrow().iter() { - document.animations().send_pending_events(); + document.update_animation_timeline(); } for (_, document) in self.documents.borrow().iter() { - document.update_animation_timeline(); + document.animations().send_pending_events(); } }