[Transition] Mount child in same commit when opening from unmounted#48649
Merged
siriwatknp merged 3 commits intoJun 11, 2026
Conversation
When opening from unmounted, the child was mounted in a layout effect, adding a commit where it was still null. Consumers reading a ref right after `in` flips (e.g. focus management in the vertical stepper demo) crashed. Restore react-transition-group's behavior of deriving the status during render so the child and its ref are present in the same commit.
Deploy previewhttps://deploy-preview-48649--material-ui.netlify.app/ Bundle size
Check out the code infra dashboard for more information about this PR. |
Tighten regression test: compare ref to mounted node instead of !== null, and assert onExited stays silent during the intermediate exited status.
Member
|
This seems a better way than mine #48646 |
mj12albert
approved these changes
Jun 10, 2026
mj12albert
left a comment
Member
There was a problem hiding this comment.
Looks good ~ it fixes https://deploy-preview-48649--material-ui.netlify.app/material-ui/react-stepper/
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.
closes #48637
Summary
Fixes the
VerticalLinearStepperdemo crash introduced by the customTransitioncomponent (#48325).Root cause
When opening from
unmounted, the newinternal/Transitionmoved the child fromunmounted → exitedinside a layout effect, adding a commit where the child is stillnull.react-transition-groupderived that status from props during render, so the child existed in the same commitinflipped true.The stepper demo focuses a button synchronously in a passive effect right after
activeStepchanges. With the extra commit, the previous step's button is already unmounted and the new one isn't mounted yet, socontinueButtonRef.currentisnulland.focus()throws.This is a silent behavior regression for any consumer that reads a ref (focus management, measurement, scroll-into-view) right after
intoggles — not just this demo.Fix
Move the
unmounted → exitedtransition to a guarded render-phase update so the child is committed (and its ref attached) in the same commitinturns true, matchingreact-transition-group. The redundantunmountedbranch is removed from the reconcile effect. No demo change needed.Testing
Added a regression test mirroring the demo's exact pattern (a parent passive effect reads the child ref right after
inflips). It fails (null) without the fix and passes with it.Verified green:
Transition,Collapse,StepContent,Fade,Grow,Zoom,Slide,Accordion,Snackbar,Tooltip,Dialog,Drawer,Menu,Popover,SpeedDial,TouchRipple,Ripple.