Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix transition enter bug #1519

Merged
merged 1 commit into from
May 28, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -339,7 +339,8 @@ let TransitionRoot = forwardRefWithAs(function Transition<
>(props: TransitionChildProps<TTag> & { show?: boolean; appear?: boolean }, ref: Ref<HTMLElement>) {
// @ts-expect-error
let { show, appear = false, unmount, ...theirProps } = props as typeof props
let transitionRef = useSyncRefs(ref)
let internalTransitionRef = useRef<HTMLElement | null>(null)
let transitionRef = useSyncRefs(internalTransitionRef, ref)

// The TransitionChild will also call this hook, and we have to make sure that we are ready.
useServerHandoffComplete()
Expand Down Expand Up @@ -390,6 +391,15 @@ let TransitionRoot = forwardRefWithAs(function Transition<
setState(TreeStates.Visible)
} else if (!hasChildren(nestingBag)) {
setState(TreeStates.Hidden)
} else {
let node = internalTransitionRef.current
if (!node) return
let rect = node.getBoundingClientRect()

if (rect.x === 0 && rect.y === 0 && rect.width === 0 && rect.height === 0) {
// The node is completely hidden, let's hide it
setState(TreeStates.Hidden)
}
}
}, [show, nestingBag])

Expand Down
11 changes: 0 additions & 11 deletions packages/@headlessui-react/src/hooks/use-transition.ts
Original file line number Diff line number Diff line change
Expand Up @@ -72,17 +72,6 @@ export function useTransition({
if (latestDirection.current === 'idle') return // We don't need to transition
if (!mounted.current) return

dd.add(() => {
if (!node) return

let rect = node.getBoundingClientRect()

if (rect.x === 0 && rect.y === 0 && rect.width === 0 && rect.height === 0) {
// The node is completely hidden
onStop.current(latestDirection.current)
}
})

dd.dispose()

beforeEvent()
Expand Down