Skip to content

[DOM] Add support for onAnimationCancel - #37609

Merged
hoxyq merged 1 commit into
react:mainfrom
connorshea:add-animationcancel-event
Sep 13, 2026
Merged

hoxyq merged 1 commit into
react:mainfrom
connorshea:add-animationcancel-event

Conversation

@connorshea

Copy link
Copy Markdown
Contributor

Summary

AI Disclosure: This was assisted using Claude Code, Fable 5.1. This PR description was fully written by me, manually, and the code was reviewed and tested by me manually.

This improves the accuracy of the animation-related event props supported by React.

This adds onAnimationCancel alongside the existing onAnimationStart, onAnimationIteration, and onAnimationEnd props.

Adds onAnimationCancel to React DOM, completing the animation event family alongside onAnimationStart, onAnimationIteration, and onAnimationEnd. animationcancel is a CSS Animations Level 1 event fired when an animation stops before it has completed.

This changeset is based on the similar changes in #27345 for the transition events.

Note that MDN's browser compat data currently claims that this is not supported in Chrome or Edge (at least not as onanimationcancel), but this change will work in Chrome 83+ due to React passing things through addEventListener anyway, and also the MDN docs are outdated about this, Chrome has started supporting onanimationcancel directly since earlier this year.

Also note that the animation and transition events on DOMEventName can probably be made to no longer do this vendor prefixing dance? I didn't do that in this PR and it should be done separately, but they've not been prefixed in a long time now and the comment rationalizing the current code mentions Android 4.x, which was last released over a decade ago now. So it seems like something that has just never been cleaned up.

How did you test this change?

  • Added tests to match the sibling properties' tests.
  • Ran yarn test, yarn lint, and yarn prettier and all passed.

Adds `onAnimationCancel` to React DOM, completing the animation event
family alongside `onAnimationStart`, `onAnimationIteration`, and
`onAnimationEnd`. `animationcancel` is a standard CSS Animations Level 1
event fired when an animation stops before it completes. This mirrors
what react#27345 did for `transitionrun`, `transitionstart`, and
`transitioncancel`.

The event is registered as a simple event, mapped to
`SyntheticAnimationEvent` so handlers receive `animationName`,
`elapsedTime`, and `pseudoElement`, and included in the vendor prefix
handling used by the other animation events.

Note: while adding this, I noticed that `SimpleEventPlugin` only maps
`transitionend` to `SyntheticTransitionEvent`. The `transitionrun`,
`transitionstart`, and `transitioncancel` events added in react#27345 fall
through to the base `SyntheticEvent`, so their handlers do not get
`propertyName`, `elapsedTime`, or `pseudoElement`. That is left as is
here to keep this change scoped, but it is likely worth a follow-up.

Co-Authored-By: Claude Fable 5.1 <[email protected]>
@meta-cla

meta-cla Bot commented Sep 11, 2026

Copy link
Copy Markdown

Hi @connorshea!

Thank you for your pull request and welcome to our community.

Action Required

In order to merge any pull request (code, docs, etc.), we require contributors to sign our Contributor License Agreement, and we don't seem to have one on file for you.

Process

In order for us to review and merge your suggested changes, please sign at https://code.facebook.com/cla. If you are contributing on behalf of someone else (eg your employer), the individual CLA may not be sufficient and your employer may need to sign the corporate CLA.

Once the CLA is signed, our tooling will perform checks and validations. Afterwards, the pull request will be tagged with CLA signed. The tagging process may take up to 1 hour after signing. Please give it that time before contacting us about it.

If you have received this in error or have any questions, please contact us at [email protected]. Thanks!

@github-actions

github-actions Bot commented Sep 11, 2026 •

Copy link
Copy Markdown

Comparing: 019019b...1f8b3e1

Critical size changes

Includes critical production bundles, as well as any change greater than 2%:

Name +/- Base Current +/- gzip Base gzip Current gzip
oss-stable/react-dom/cjs/react-dom.production.js = 7.35 kB 7.35 kB = 1.96 kB 1.96 kB
oss-stable/react-dom/cjs/react-dom-client.production.js +0.05% 625.31 kB 625.60 kB +0.04% 110.54 kB 110.58 kB
oss-experimental/react-dom/cjs/react-dom.production.js = 7.36 kB 7.36 kB +0.05% 1.96 kB 1.96 kB
oss-experimental/react-dom/cjs/react-dom-client.production.js +0.04% 696.53 kB 696.81 kB +0.03% 121.97 kB 122.01 kB
facebook-www/ReactDOM-prod.classic.js +0.04% 715.28 kB 715.56 kB +0.03% 125.20 kB 125.24 kB
facebook-www/ReactDOM-prod.modern.js +0.04% 705.60 kB 705.88 kB +0.03% 123.63 kB 123.67 kB

Significant size changes

Includes any change greater than 0.2%:

(No significant changes)

Generated by sizebot against 1f8b3e1

@meta-cla meta-cla Bot added the CLA Signed label Sep 12, 2026
@meta-cla

meta-cla Bot commented Sep 12, 2026

Copy link
Copy Markdown

Thank you for signing our Contributor License Agreement. We can now accept your code for this (and any) Meta Open Source project. Thanks!

@hoxyq
hoxyq requested a review from eps1lon September 13, 2026 09:48
@hoxyq

hoxyq commented Sep 13, 2026

Copy link
Copy Markdown
Collaborator

Thank you!

@hoxyq
hoxyq merged commit 564923c into react:main Sep 13, 2026
245 checks passed
github-actions Bot pushed a commit that referenced this pull request Sep 13, 2026
## Summary

AI Disclosure: This was assisted using Claude Code, Fable 5.1. This PR
description was fully written by me, manually, and the code was reviewed
and tested by me manually.

This improves the accuracy of the animation-related event props
supported by React.

This adds `onAnimationCancel` alongside the existing `onAnimationStart`,
`onAnimationIteration`, and `onAnimationEnd` props.

Adds `onAnimationCancel` to React DOM, completing the animation event
family alongside `onAnimationStart`, `onAnimationIteration`, and
`onAnimationEnd`.
[`animationcancel`](https://developer.mozilla.org/en-US/docs/Web/API/Element/animationcancel_event)
is a CSS Animations Level 1 event fired when an animation stops before
it has completed.

This changeset is based on the similar changes in #27345 for the
transition events.

Note that MDN's browser compat data [currently
claims](https://developer.mozilla.org/en-US/docs/Web/API/Element/animationcancel_event)
that this is not supported in Chrome or Edge (at least not as
`onanimationcancel`), but this change will work in Chrome 83+ due to
React passing things through `addEventListener` anyway, and also the MDN
docs are [outdated about
this](mdn/browser-compat-data#29376), Chrome
has started supporting `onanimationcancel` directly [since earlier this
year](https://issues.chromium.org/issues/41404325).

Also note that the animation and transition events on DOMEventName can
probably be made to no longer do this vendor prefixing dance? I didn't
do that in this PR and it should be done separately, but they've not
been prefixed in a long time now and the comment rationalizing the
current code mentions Android 4.x, which was last released over a decade
ago now. So it seems like something that has just never been cleaned up.

## How did you test this change?

- Added tests to match the sibling properties' tests.
- Ran `yarn test`, `yarn lint`, and `yarn prettier` and all passed.

Co-authored-by: Claude Fable 5.1 <[email protected]>

DiffTrain build for [564923c](564923c)
github-actions Bot pushed a commit that referenced this pull request Sep 13, 2026
## Summary

AI Disclosure: This was assisted using Claude Code, Fable 5.1. This PR
description was fully written by me, manually, and the code was reviewed
and tested by me manually.

This improves the accuracy of the animation-related event props
supported by React.

This adds `onAnimationCancel` alongside the existing `onAnimationStart`,
`onAnimationIteration`, and `onAnimationEnd` props.

Adds `onAnimationCancel` to React DOM, completing the animation event
family alongside `onAnimationStart`, `onAnimationIteration`, and
`onAnimationEnd`.
[`animationcancel`](https://developer.mozilla.org/en-US/docs/Web/API/Element/animationcancel_event)
is a CSS Animations Level 1 event fired when an animation stops before
it has completed.

This changeset is based on the similar changes in #27345 for the
transition events.

Note that MDN's browser compat data [currently
claims](https://developer.mozilla.org/en-US/docs/Web/API/Element/animationcancel_event)
that this is not supported in Chrome or Edge (at least not as
`onanimationcancel`), but this change will work in Chrome 83+ due to
React passing things through `addEventListener` anyway, and also the MDN
docs are [outdated about
this](mdn/browser-compat-data#29376), Chrome
has started supporting `onanimationcancel` directly [since earlier this
year](https://issues.chromium.org/issues/41404325).

Also note that the animation and transition events on DOMEventName can
probably be made to no longer do this vendor prefixing dance? I didn't
do that in this PR and it should be done separately, but they've not
been prefixed in a long time now and the comment rationalizing the
current code mentions Android 4.x, which was last released over a decade
ago now. So it seems like something that has just never been cleaned up.

## How did you test this change?

- Added tests to match the sibling properties' tests.
- Ran `yarn test`, `yarn lint`, and `yarn prettier` and all passed.

Co-authored-by: Claude Fable 5.1 <[email protected]>

DiffTrain build for [564923c](564923c)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants