@@ -170,20 +170,28 @@ export const machine = createMachine<PresenceSchema>({
170170 }
171171
172172 const onEnd = ( event : AnimationEvent ) => {
173+ const animationName = getAnimationName ( refs . get ( "styles" ) )
173174 const target = getEventTarget ( event )
174- if ( target === node && event . animationName === context . get ( "unmountAnimationName" ) && ! prop ( "present" ) ) {
175+ if ( target === node && animationName === context . get ( "unmountAnimationName" ) && ! prop ( "present" ) ) {
175176 send ( { type : "UNMOUNT" , src : "animationend" } )
176177 }
177178 }
178179
180+ const onCancel = ( event : AnimationEvent ) => {
181+ const target = getEventTarget ( event )
182+ if ( target === node && ! prop ( "present" ) ) {
183+ send ( { type : "UNMOUNT" , src : "animationcancel" } )
184+ }
185+ }
186+
179187 node . addEventListener ( "animationstart" , onStart )
180- node . addEventListener ( "animationcancel" , onEnd )
188+ node . addEventListener ( "animationcancel" , onCancel )
181189 node . addEventListener ( "animationend" , onEnd )
182190 const cleanupStyles = setStyle ( node , { animationFillMode : "forwards" } )
183191
184192 return ( ) => {
185193 node . removeEventListener ( "animationstart" , onStart )
186- node . removeEventListener ( "animationcancel" , onEnd )
194+ node . removeEventListener ( "animationcancel" , onCancel )
187195 node . removeEventListener ( "animationend" , onEnd )
188196 nextTick ( ( ) => cleanupStyles ( ) )
189197 }
0 commit comments