Skip to content

Commit d330a9d

Browse files
Preparing runAfterTransition for Strict-mode (#5569)
* prepare runAfterTransition for strict-mode
1 parent 2119bbb commit d330a9d

File tree

1 file changed

+15
-3
lines changed

1 file changed

+15
-3
lines changed

packages/@react-aria/utils/src/runAfterTransition.ts

Lines changed: 15 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,14 @@ function setupGlobalEvents() {
2626
return;
2727
}
2828

29-
let onTransitionStart = (e: TransitionEvent) => {
29+
function isTransitionEvent(event: Event): event is TransitionEvent {
30+
return 'propertyName' in event;
31+
}
32+
33+
let onTransitionStart = (e: Event) => {
34+
if (!isTransitionEvent(e) || !e.target) {
35+
return;
36+
}
3037
// Add the transitioning property to the list for this element.
3138
let transitions = transitionsByElement.get(e.target);
3239
if (!transitions) {
@@ -36,13 +43,18 @@ function setupGlobalEvents() {
3643
// The transitioncancel event must be registered on the element itself, rather than as a global
3744
// event. This enables us to handle when the node is deleted from the document while it is transitioning.
3845
// In that case, the cancel event would have nowhere to bubble to so we need to handle it directly.
39-
e.target.addEventListener('transitioncancel', onTransitionEnd);
46+
e.target.addEventListener('transitioncancel', onTransitionEnd, {
47+
once: true
48+
});
4049
}
4150

4251
transitions.add(e.propertyName);
4352
};
4453

45-
let onTransitionEnd = (e: TransitionEvent) => {
54+
let onTransitionEnd = (e: Event) => {
55+
if (!isTransitionEvent(e) || !e.target) {
56+
return;
57+
}
4658
// Remove property from list of transitioning properties.
4759
let properties = transitionsByElement.get(e.target);
4860
if (!properties) {

0 commit comments

Comments
 (0)