diff --git a/third_party/blink/renderer/core/animation/animation.cc b/third_party/blink/renderer/core/animation/animation.cc index 18bfff861f6b17..63c6e37019de65 100644 --- a/third_party/blink/renderer/core/animation/animation.cc +++ b/third_party/blink/renderer/core/animation/animation.cc @@ -2320,10 +2320,6 @@ bool Animation::Update(TimingUpdateReason reason) { if (reason == kTimingUpdateForAnimationFrame) { if (idle || CalculateAnimationPlayState() == kFinished) { - // TODO(crbug.com/1029348): Per spec, we should have a microtask - // checkpoint right after the update cycle. Once this is fixed we should - // no longer need to force a synchronous resolution here. - AsyncFinishMicrotask(); finished_ = true; } } diff --git a/third_party/blink/renderer/core/animation/document_animations.cc b/third_party/blink/renderer/core/animation/document_animations.cc index 32cfdff88acf1e..1eb731c5fc91be 100644 --- a/third_party/blink/renderer/core/animation/document_animations.cc +++ b/third_party/blink/renderer/core/animation/document_animations.cc @@ -49,6 +49,7 @@ #include "third_party/blink/renderer/core/page/page_animator.h" #include "third_party/blink/renderer/core/style/computed_style.h" #include "third_party/blink/renderer/platform/bindings/microtask.h" +#include "third_party/blink/renderer/platform/heap/persistent.h" namespace blink { @@ -260,10 +261,13 @@ void DocumentAnimations::RemoveReplacedAnimations( // The list of animations for removal is constructed in reverse composite // ordering for efficiency. Flip the ordering to ensure that events are - // dispatched in composite order. + // dispatched in composite order. Queue as a microtask so that the finished + // event is dispatched ahead of the remove event. for (auto it = animations_to_remove.rbegin(); it != animations_to_remove.rend(); it++) { - (*it)->RemoveReplacedAnimation(); + Animation* animation = *it; + Microtask::EnqueueMicrotask(WTF::Bind(&Animation::RemoveReplacedAnimation, + WrapWeakPersistent(animation))); } }