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

Ensure TransitionRoot component without props transitions correctly #3147

Merged
merged 2 commits into from Apr 26, 2024

Conversation

RobinMalfait
Copy link
Collaborator

We recently made a change that the Transition component renders a Fragment by default. We also made sure that a TransitionRoot component (which could exist for orchestration purposes for child transitions) doesn't render a DOM node when it doesn't need to. This is the case if it doesn't have any enter, enterFrom, enterTo, leave, leaveFrom, or leaveTo props.

However, this caused a bug where the Transition component doesn't properly mount or unmount its children when the TransitionRoot component doesn't render a DOM node. This is because the Transition component relies on DOM transition events and will call the onStart and onStop callbacks when the transition starts and ends.

To solve this, we make sure to still call the onStart and onStop callbacks, because you can think of it as the transition was done immediately.

A bit of a weird one, but you can use the `TransitionRoot` component
without any props for transitions themselves (so no real transition can
happen). Even crazier, it can happen that it doesn't even render a DOM
node, but just its children.

At this point, the `TransitionRoot` component is purely there for
orchestration purposes of child components.

Since there is no DOM node in certain situations, the transitions (and
its `onStart` and `onStop` callbacks) won't even happen at all. This
causes a bug (obvious in react strict mode) where children don't
properly mount or the transition component doesn't properly unmount.
Copy link

vercel bot commented Apr 26, 2024

The latest updates on your projects. Learn more about Vercel for Git ↗︎

Name Status Preview Comments Updated (UTC)
headlessui-react ✅ Ready (Inspect) Visit Preview 💬 Add feedback Apr 26, 2024 9:12pm
headlessui-vue ✅ Ready (Inspect) Visit Preview 💬 Add feedback Apr 26, 2024 9:12pm

@RobinMalfait RobinMalfait merged commit afc9cb6 into main Apr 26, 2024
8 checks passed
@RobinMalfait RobinMalfait deleted the fix/transition-root branch April 26, 2024 21:28
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

2 participants