Skip to content
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

Merged
merged 4 commits into from
Dec 14, 2021

Conversation

averyjohnston
Copy link
Contributor

@averyjohnston averyjohnston commented Dec 13, 2021

Pull request checklist

Please check if your PR fulfills the following requirements:

  • Tests for the changes have been added (for bug fixes / features)
  • Docs have been reviewed and added / updated if needed (for bug fixes / features)
  • Build (npm run build) was run locally and any changes were pushed
  • Lint (npm run lint) has passed locally and any fixes were made for failures

Pull request type

Please check the type of change your PR introduces:

  • Bugfix
  • Feature
  • Code style update (formatting, renaming)
  • Refactoring (no functional changes, no api changes)
  • Build related changes
  • Documentation content changes
  • Other (please describe):

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 the await 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?

  • Yes
  • No

Other information

Copy link
Contributor

@sean-perkins sean-perkins left a 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.

@liamdebeasi liamdebeasi changed the base branch from next to main December 13, 2021 17:17
@liamdebeasi liamdebeasi requested a review from a team as a code owner December 13, 2021 17:17
Copy link
Contributor

@liamdebeasi liamdebeasi left a 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?

@averyjohnston
Copy link
Contributor Author

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.

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: opening modal quickly results in white screen
3 participants