fix(core): expose new phase to useTransition render fn#2507
Merged
Conversation
Previously `t.phase` was only mutated to the new phase inside a useIsomorphicLayoutEffect, so the render fn always saw the previous phase during the render that triggered the leave animation. The next render that would have surfaced `'leave'` was suppressed because the transition had already expired and been pruned, leaving consumers unable to branch on `state.phase === 'leave'`. Read the upcoming phase from the changes map (or exitingTransitions when exitBeforeEnter is set) and pass a shallow copy of the transition state with that phase to the render fn. No state mutation during render; no API change. Closes #1654.
|
The latest updates on your projects. Learn more about Vercel for GitHub.
|
🦋 Changeset detectedLatest commit: 5b19e9c The changes in this PR will be included in the next version bump. This PR includes changesets to release 12 packages
Not sure what this means? Click here to learn what changesets are. Click here if you're a maintainer who wants to add another changeset to this PR |
This was referenced May 22, 2026
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.
Summary
In
useTransition, the render fn's third argument exposesstate.phaseso callers can branch on lifecycle (e.g.state.phase === 'leave'). Previously this phase was only mutated inside a layout effect that runs after render, so during the render that triggered the leave animation the consumer always saw the stale'enter'. By the time a follow-up render could have surfaced'leave', the transition had been marked expired and pruned — so'leave'was effectively unreachable for normal removals, only briefly observable when an item was re-added mid-leave.Fix
In the render loop, read the upcoming phase from the
changesmap (orexitingTransitionswhenexitBeforeEnteris set) and pass a shallow copy of the transition state with that phase to the render fn. No state mutation during render; no API change; the existing layout effect still owns the canonical mutation.Regression test in
useTransition.test.tsxremoves an item and asserts the render fn observedphase === 'leave'at some point during a normal removal — fails onnext, passes with this change.Closes #1654.