Skip to content

Commit

Permalink
ensure Transition component works when nothing is transitioning
Browse files Browse the repository at this point in the history
  • Loading branch information
RobinMalfait committed Feb 28, 2023
1 parent 9aacb50 commit a47f601
Showing 1 changed file with 17 additions and 0 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,23 @@ function waitForTransition(node: HTMLElement, done: () => void) {
dispose()
}, totalDuration)
} else {
d.group((d) => {
// Mark the transition as done when the timeout is reached. This is a fallback in case the
// transitionrun event is not fired.
d.setTimeout(() => {
done()
d.dispose()
}, totalDuration)

// The moment the transitionrun event fires, we should cleanup the timeout fallback, because
// then we know that we can use the native transition events because something is
// transitioning.
d.addEventListener(node, 'transitionrun', (event) => {
if (event.target !== event.currentTarget) return
d.dispose()
})
})

let dispose = d.addEventListener(node, 'transitionend', (event) => {
if (event.target !== event.currentTarget) return
done()
Expand Down

0 comments on commit a47f601

Please sign in to comment.