Skip to content

Commit

Permalink
improve requiresRef check
Browse files Browse the repository at this point in the history
Also ensure that a ref is required if the `as` prop is provided and
it's not a `Fragment`
  • Loading branch information
RobinMalfait committed Apr 18, 2024
1 parent 3fb4a9d commit 40370c4
Showing 1 changed file with 11 additions and 2 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -292,7 +292,15 @@ function TransitionChildFn<TTag extends ElementType = typeof DEFAULT_TRANSITION_
...rest
} = props as typeof props
let container = useRef<HTMLElement | null>(null)
let requiresRef = Boolean(enter || enterFrom || enterTo || leave || leaveFrom || leaveTo)
let requiresRef = Boolean(
enter ||
enterFrom ||
enterTo ||
leave ||
leaveFrom ||
leaveTo ||
(props.as ?? DEFAULT_TRANSITION_CHILD_TAG) !== Fragment
)
let transitionRef = useSyncRefs(...(requiresRef ? [container, ref] : ref === null ? [] : [ref]))
let strategy = rest.unmount ?? true ? RenderStrategy.Unmount : RenderStrategy.Hidden

Expand Down Expand Up @@ -504,7 +512,8 @@ function TransitionRootFn<TTag extends ElementType = typeof DEFAULT_TRANSITION_C
props.enterTo ||
props.leave ||
props.leaveFrom ||
props.leaveTo
props.leaveTo ||
(props.as ?? DEFAULT_TRANSITION_CHILD_TAG) !== Fragment
)
let transitionRef = useSyncRefs(
...(requiresRef ? [internalTransitionRef, ref] : ref === null ? [] : [ref])
Expand Down

0 comments on commit 40370c4

Please sign in to comment.