fix: Schedule .modal("hide")
for transitioning modals
#4173
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Fixes posit-dev/py-shiny#1318 for real.
The core issue is that calling
$el.modal('hide')
on a modal element$el
that hasn't been fully revealed yet doesn't work. In practice, this means that if a modal is shown and hidden within 300ms (the default modal transition time) the.modal('hide')
call silently does nothing.This solution in this PR is to use the
show.bs.modal
event that fires at the start of the modal transition to track modals that are currently in a state of transition. When theshown.bs.modal
event fires, we remove the modal from the set.Separately, for
removeModal()
calls, if we receive a remove modal message that intends to remove a modal currently in the set of transitioning modals, then rather than calling.modal('hide')
directly, we instead schedule to it to be called when theshown.bs.modal
event occurs. This avoids any kind of race condition and guarantees that the current modal will be hidden as soon as the transition is complete. (From a UI perspective, this also avoids jarring transitions.)Example app: