Skip to content

Commit

Permalink
Rely on initial state of Transition component (#882)
Browse files Browse the repository at this point in the history
The `useId` hook causes a re-render in TransitionChild immediately after mount which triggers a transition by `initial` being false in the second re-render regardless of how `appear` was set.
  • Loading branch information
dcastil authored Oct 29, 2021
1 parent 9f638c9 commit fd4669f
Showing 1 changed file with 3 additions and 3 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,7 @@ function useSplitClasses(classes: string = '') {
interface TransitionContextValues {
show: boolean
appear: boolean
initial: boolean
}
let TransitionContext = createContext<TransitionContextValues | null>(null)
TransitionContext.displayName = 'TransitionContext'
Expand Down Expand Up @@ -213,10 +214,9 @@ function TransitionChild<TTag extends ElementType = typeof DEFAULT_TRANSITION_CH
let [state, setState] = useState(TreeStates.Visible)
let strategy = rest.unmount ? RenderStrategy.Unmount : RenderStrategy.Hidden

let { show, appear } = useTransitionContext()
let { show, appear, initial } = useTransitionContext()
let { register, unregister } = useParentNesting()

let initial = useIsInitialRender()
let id = useId()

let isTransitioning = useRef(false)
Expand Down Expand Up @@ -371,7 +371,7 @@ export function Transition<TTag extends ElementType = typeof DEFAULT_TRANSITION_

let initial = useIsInitialRender()
let transitionBag = useMemo<TransitionContextValues>(
() => ({ show: show as boolean, appear: appear || !initial }),
() => ({ show: show as boolean, appear: appear || !initial, initial }),
[show, appear, initial]
)

Expand Down

0 comments on commit fd4669f

Please sign in to comment.