-
Notifications
You must be signed in to change notification settings - Fork 13.5k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
fix(modal): fix timing issue when rapidly closing and opening controller modal #24380
Conversation
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Everything looks great from the reproduction app/solving the issue, nice work!
Anything we can do to solve the issue of these inserted comments not being cleaned up (they get inserted next to ion-modal
in the DOM)?
<!--teleport start-->
<!--teleport end-->
<!--teleport start-->
<!--teleport end-->
I believe that's a responsibility of the framework delegate that may not be called anymore with the change for controller-based modals.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
It looks like there is a race condition in https://github.com/ionic-team/ionic-framework/blob/main/core/src/components/modal/modal.tsx#L495 where we the present method is allowed to proceed even though the dismiss method is not complete because we only await the animation.
I think what I was trying to do at the time was implement a locking system where only one method can be called at a time, and subsequent calls wait for the previous method to finish. Unfortunately, I only leveraged the actual transition, forgetting that there are other async calls that we need to wait for.
This patch does resolve the behavior noted in the issue, but it does not resolve the underlying race condition, so I was hoping we could resolve the race condition before we merge.
In terms of a different approach to fixing this, I am thinking we implement what the router-outlet
component has currently: https://github.com/ionic-team/ionic-framework/blob/main/core/src/components/router-outlet/route-outlet.tsx#L240-L249
This creates a lock for a single commit
call and is unlocked only when the unlock
callback is called: https://github.com/ionic-team/ionic-framework/blob/main/core/src/components/router-outlet/route-outlet.tsx#L134
This would allow us to both resolve the race condition and the issue that reported this. Also, because popover uses the same currentTransition
logic that the modal does, this race condition is probably there too. Happy to discuss more. Thoughts?
The lock/unlock method didn't work; Liam and I spent a bunch of time debugging and couldn't find the source of the problem. We'll go with the original strategy for now. I've created an internal ticket to try and solve the race condition directly in the long term. Will add more details there. |
Pull request checklist
Please check if your PR fulfills the following requirements:
npm run build
) was run locally and any changes were pushednpm run lint
) has passed locally and any fixes were made for failuresPull request type
Please check the type of change your PR introduces:
What is the current behavior?
Issue Number: Resolves #24230
If a controller modal is re-opened immediately after dismissing, the call to
detachComponent
that unmounts the user's modal content doesn't trigger until after the present animation (due to theawait this.currentTransition
line above it). This causes the modal to present, and then immediately unmount its content.This issue only happens with controller modals; inline modals are unaffected. It also doesn't happen in core, only frameworks like Vue.
What is the new behavior?
The
detachComponent
call is only made for inline modals. It isn't needed for controller modals anyway, because by that point, the entire modal (including the user's element) has already been removed from the DOM.Does this introduce a breaking change?
Other information