Skip to content

fix(menu): cancel pending swipe when animating - #31840

Open
HerrDerb wants to merge 1 commit into
ionic-team:mainfrom
HerrDerb:menu-cancel-pending-swipe-on-programmatic-animation
Open

HerrDerb wants to merge 1 commit into
ionic-team:mainfrom
HerrDerb:menu-cancel-pending-swipe-on-programmatic-animation

Conversation

@HerrDerb

Copy link
Copy Markdown

Issue number: resolves #31839


What is the current behavior?

ion-menu throws ASSERT: _before() should not be called while animating when the menu is opened or closed from code (open(), close(), toggle(), a backdrop click) while a pointer that went down before is still on the screen, and that pointer then moves.

The swipe gesture checks canStart() only on pointer down, when the menu is not animating yet. When the pointer passes the threshold during the animation, the gesture is captured and onWillStart() calls beforeAnimation() a second time.

What is the new behavior?

  • _setOpen() resets the swipe gesture before it starts an animation (gesture.enable(false), then gesture.enable(swipeGesture)). A pointer that went down before the animation no longer becomes a swipe, so beforeAnimation() is not called twice.
  • The menu opens and closes as before, and swipes that start after the animation work as before.
  • New e2e test menu/test/gesture: the pointer goes down, the menu opens or closes from code, then the pointer drags. Both cases throw on main in Chromium, Firefox and WebKit and pass with this change. The test page loads with ionic:_testing=false, because the race needs a running animation.

Does this introduce a breaking change?

  • Yes
  • No

Other information

A check for isAnimating in onWillStart() alone would not be enough: the gesture would still call onStart() and onMove() on the animation started from code.

Reproduction app: https://github.com/HerrDerb/ionic-framework/tree/menu-swipe-race-reproduction

@HerrDerb
HerrDerb requested a review from a team as a code owner November 26, 2026 09:55
@HerrDerb
HerrDerb requested a review from thetaPC November 26, 2026 09:55
@vercel

vercel Bot commented Nov 26, 2026

Copy link
Copy Markdown

@HerrDerb is attempting to deploy a commit to the Ionic Team on Vercel.

A member of the Team first needs to authorize it.

@github-actions github-actions Bot added the package: core @ionic/core package label Nov 26, 2026
Reset the swipe gesture when the menu opens or closes from code. A
pointer that went down before the animation has already passed
canStart, so moving it past the threshold called beforeAnimation a
second time and threw "_before() should not be called while animating".

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
@HerrDerb
HerrDerb force-pushed the menu-cancel-pending-swipe-on-programmatic-animation branch from e8d5967 to c32ec51 Compare November 26, 2026 11:10

This branch has not been deployed

No deployments
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

package: core @ionic/core package

Projects

None yet

Development

Successfully merging this pull request may close these issues.

bug: menu throws "_before() should not be called while animating" when opened or closed from code during a touch

1 participant