Repository navigation
Ensure Transition unmounts when its reversed transition starts late - #3906
Open
SahinurDEV wants to merge 2 commits into
Open
SahinurDEV wants to merge 2 commits into
SahinurDEV wants to merge 2 commits into
Conversation
When a transition is reversed (e.g. closing while the enter transition is still running), we capture the running transitions one frame after flipping the flags. If React hasn't committed the flag change yet, we capture the old transitions instead of the reversed ones. Once those settle, `done()` sees the reversed transitions still running and bails out, and nothing calls it again, so the element stays mounted forever. Re-check for running transitions after the captured ones settle and keep waiting until none are left before calling `done()`. Fixes tailwindlabs#3902
|
@SahinurDEV is attempting to deploy a commit to the Tailwind Labs Team on Vercel. A member of the Team first needs to authorize it. |
This branch has not been deployed
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
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 #3902
When
showflips back while a transition is still running,useTransitionreverses it:run()flips the flags and one frame laterwaitForTransitioncapturesgetAnimations(). If React hasn't committed the flag change by then (busy main thread), we capture the old enter transitions. The commit then starts the reverse transitions, which cancels the captured ones, sodone()runs right away. Because the transition was cancelled,done()sees the reverse transitions still running and returns early, and nothing ever calls it again. The element stays mounted withdata-closed data-enter data-transitionand, for aDialog, keeps swallowing clicks.The fix: after the captured transitions settle,
waitForTransitionchecksgetAnimations()again and keeps waiting until noCSSTransitionis running, then callsdone(). The pending-transition filter (CSSTransitionthat isn'tfinished) is now shared withhasPendingTransitions, so a finished transition that is still listed can't cause a loop.The Vue package isn't affected: it waits on
transition-durationwith a timeout, not ongetAnimations().Tests
src/hooks/use-transition.test.tsx. jsdom doesn't run CSS transitions, so the test controls whatgetAnimations()returns: open, close mid-enter while only the old transition is visible, then swap in the reversed transition. Without the fix the panel stays mounted withdata-closed data-enter data-transition. With the fix it unmounts once the reversed transition finishes.npm run react test: 31 suites, 1069 passed.tsc --noEmitfor@headlessui/reactand prettier are clean.