RESOLVED FIXED 236274
Dialog element only animates once
https://bugs.webkit.org/show_bug.cgi?id=236274
Summary Dialog element only animates once
Darin Senneff
Reported 2022-02-07 17:10:10 PST
Created attachment 451176 [details] Screen capture of dialog animation bug When using a CSS animation to display a <dialog> element, the animation plays correctly the first time the <dialog> is displayed but not subsequent times. Noticed this on the Webkit blog post about the <dialog> element (https://webkit.org/blog/12209/introducing-the-dialog-element/). The demo that is animated is embedded under the "Styling" heading. I also built my own demo to confirm and am experiencing the issue there, too. Also attaching a screen capture video for reference. To replicate: 1) Open the following demo in Safari Tech Preview: https://codepen.io/dsenneff/pen/qBVRPNr/ed7774c741125ea6f486e4da13d65cf0?editors=1111 2) Click on the 'Open Dialog' button. The <dialog> transitions into view. 3) Close the <dialog>. 4) Click on the 'Open Dialog' button again. The <dialog> does not transition.
Attachments
Screen capture of dialog animation bug (3.07 MB, video/mp4)
2022-02-07 17:10 PST, Darin Senneff
no flags
Patch (14.29 KB, patch)
2022-02-09 08:10 PST, Antoine Quint
no flags
Patch for landing (14.39 KB, patch)
2022-02-09 11:16 PST, Antoine Quint
no flags
Patch (13.81 KB, patch)
2022-03-15 00:55 PDT, Antoine Quint
no flags
Patch for landing (13.86 KB, patch)
2022-03-15 03:06 PDT, Antoine Quint
no flags
Patch (14.49 KB, patch)
2022-03-18 11:42 PDT, Antoine Quint
dino: review+
ews-feeder: commit-queue-
Patch for landing (14.54 KB, patch)
2022-03-18 11:50 PDT, Antoine Quint
no flags
Radar WebKit Bug Importer
Comment 1 2022-02-08 09:50:05 PST
Antoine Quint
Comment 2 2022-02-08 11:15:30 PST
If I interrupt the animation by clicking on Cancel or Confirm while the dialog is animating, then I can re-run the animation just fine.
Antoine Quint
Comment 3 2022-02-09 08:10:28 PST
Antoine Quint
Comment 4 2022-02-09 08:12:19 PST
Submitted web-platform-tests pull request: https://github.com/web-platform-tests/wpt/pull/32773
EWS Watchlist
Comment 5 2022-02-09 08:13:13 PST
This patch modifies the imported WPT tests. Please ensure that any changes on the tests (not coming from a WPT import) are exported to WPT. Please see https://trac.webkit.org/wiki/WPTExportProcess
Tim Nguyen (:ntim)
Comment 6 2022-02-09 08:26:02 PST
Comment on attachment 451379 [details] Patch View in context: https://bugs.webkit.org/attachment.cgi?id=451379&action=review > LayoutTests/imported/w3c/web-platform-tests/css/css-animations/dialog-animation.html:12 > +dialog[open] { > + animation: dialog-open-animation 1ms; > +} Maybe `dialog` is better selector to target since it always matches. not sure? > LayoutTests/imported/w3c/web-platform-tests/css/css-animations/dialog-animation.html:20 > +<script type="text/javascript"> nit: drop type="text/javascript" > LayoutTests/imported/w3c/web-platform-tests/css/css-animations/dialog-animation.html:22 > +'use strict'; nit: double quotes for consistency with the other strings in the test > LayoutTests/imported/w3c/web-platform-tests/css/css-animations/dialog-animation.html:41 > + dialog.open = true; > + const animations = dialog.getAnimations(); > + assert_equals(animations.length, 1, "As the <dialog> is shown intially an animation is started"); > + > + await animations[0].finished; > + > + await waitForNextFrame(); > + > + dialog.open = false; > + assert_equals(dialog.getAnimations().length, 0, "As the <dialog> is closed the animation is removed"); > + > + await waitForNextFrame(); > + > + dialog.open = true; dialog.show()/dialog.close() is usually preferable, but I guess it doesn't matter for this test > LayoutTests/imported/w3c/web-platform-tests/css/css-animations/dialog-backdrop-animation.html:20 > +<script type="text/javascript"> ditto
Tim Nguyen (:ntim)
Comment 7 2022-02-09 08:30:22 PST
Comment on attachment 451379 [details] Patch View in context: https://bugs.webkit.org/attachment.cgi?id=451379&action=review > Source/WebCore/dom/Element.cpp:3451 > + if (auto* renderer = this->renderer()) { > + if (auto backdrop = renderer->backdropRenderer()) { > + if (auto styleable = Styleable::fromRenderer(*backdrop)) > + styleable->cancelDeclarativeAnimations(); > + } > + } > + Note for other reviewers: this is done here, because after backdrop renderers get destroyed after Element::removeFromTopLayer() and once they get destroyed, Styleable::fromRenderer(backdropRenderer) can't find the associated element anymore, since fromRenderer uses Document::topLayerElements() to find element renderers associated to backdrops. Another way to fix this bug would be making Styleable::fromRenderer independent from topLayerElements(), but it's not entirely trivial to do atm.
Dean Jackson
Comment 8 2022-02-09 08:56:40 PST
Comment on attachment 451379 [details] Patch r=me based on Tim's review
Simon Fraser (smfr)
Comment 9 2022-02-09 09:22:02 PST
Comment on attachment 451379 [details] Patch View in context: https://bugs.webkit.org/attachment.cgi?id=451379&action=review >> Source/WebCore/dom/Element.cpp:3451 >> + > > Note for other reviewers: this is done here, because after backdrop renderers get destroyed after Element::removeFromTopLayer() > > and once they get destroyed, Styleable::fromRenderer(backdropRenderer) can't find the associated element anymore, since fromRenderer uses Document::topLayerElements() to find element renderers associated to backdrops. > > Another way to fix this bug would be making Styleable::fromRenderer independent from topLayerElements(), but it's not entirely trivial to do atm. If you have to explain this to other reviewers, then maybe the code needs to explain it in the form of a comment.
Antoine Quint
Comment 10 2022-02-09 11:16:03 PST
Created attachment 451413 [details] Patch for landing
EWS
Comment 11 2022-02-09 12:49:25 PST
Committed r289498 (247036@main): <https://commits.webkit.org/247036@main> All reviewed patches have been landed. Closing bug and clearing flags on attachment 451413 [details].
WebKit Commit Bot
Comment 12 2022-02-11 17:10:56 PST
Re-opened since this is blocked by bug 236534
Tim Nguyen (:ntim)
Comment 13 2022-02-12 11:21:55 PST
Comment on attachment 451413 [details] Patch for landing View in context: https://bugs.webkit.org/attachment.cgi?id=451413&action=review > Source/WebCore/dom/Element.cpp:3446 > + // We need to call Styleable::fromRenderer() while this document is still contained > + // in Document::topLayerElements(). This comment would be more accurate: // We need to call Styleable::fromRenderer() while this element is still contained in // Document::topLayerElements(), since Styleable::fromRenderer() relies on this to // find the backdrop's associated element.
Antoine Quint
Comment 14 2022-03-15 00:55:14 PDT
Antoine Quint
Comment 15 2022-03-15 01:08:22 PDT
(In reply to Tim Nguyen (:ntim) from comment #13) > Comment on attachment 451413 [details] > Patch for landing > > View in context: > https://bugs.webkit.org/attachment.cgi?id=451413&action=review > > > Source/WebCore/dom/Element.cpp:3446 > > + // We need to call Styleable::fromRenderer() while this document is still contained > > + // in Document::topLayerElements(). > > This comment would be more accurate: > > // We need to call Styleable::fromRenderer() while this element is still > contained in > // Document::topLayerElements(), since Styleable::fromRenderer() relies > on this to > // find the backdrop's associated element. I used that comment in the new patch.
Antoine Quint
Comment 16 2022-03-15 03:06:28 PDT
Created attachment 454685 [details] Patch for landing
EWS
Comment 17 2022-03-15 04:41:09 PDT
Committed r291282 (248421@main): <https://commits.webkit.org/248421@main> All reviewed patches have been landed. Closing bug and clearing flags on attachment 454685 [details].
WebKit Commit Bot
Comment 18 2022-03-15 15:06:19 PDT
Re-opened since this is blocked by bug 237924
Antoine Quint
Comment 19 2022-03-18 11:39:33 PDT
I think I worked out the performance regression, the issue was that we'd added a call to `setAnimationsCreatedByMarkup({ })` under `Styleable::cancelDeclarativeAnimations()` and this would force the creation of ElementAnimationRareData for the wrapper element even if there were no pre-existing data stored for it. I will now upload a new patch which appears to address Speedometer performance concerns.
Antoine Quint
Comment 20 2022-03-18 11:42:29 PDT
Antoine Quint
Comment 21 2022-03-18 11:50:23 PDT
Created attachment 455119 [details] Patch for landing
EWS
Comment 22 2022-03-19 06:25:06 PDT
Committed r291527 (248633@main): <https://commits.webkit.org/248633@main> All reviewed patches have been landed. Closing bug and clearing flags on attachment 455119 [details].
Antoine Quint
Comment 23 2022-04-13 12:36:23 PDT
This caused bug 239291.
Brent Fulgham
Comment 24 2022-05-26 14:50:00 PDT
This fix shipped with Safari 15.5 (all platforms).
Note You need to log in before you can comment on or make changes to this bug.