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 React <Transition> flicker issue #1118

Merged
merged 4 commits into from
Mar 1, 2022
Merged

Conversation

thecrypticace
Copy link
Contributor

I think I figured it out! (I hope)

Basically the transition component's show defaulted to true — which is fine. However, we also have an initial render check. This means that the transition doesn't run on first render. But if you trigger a re-render of children without a change in the show state it'll run the enter transition.

This means that:

  1. If an item is already visible
  2. The enter from is opacity-0

Then the transition starts and assumes that the element is invisible. This causes the weird animation flicker where it goes from visible to quickly not visible to visible again. The solution is to store the previous show state and only transition if it is actually different.

@vercel
Copy link

vercel bot commented Feb 18, 2022

This pull request is being automatically deployed with Vercel (learn more).
To see the status of your deployments, click below or on the icon next to each commit.

headlessui-react – ./packages/playground-react

🔍 Inspect: https://vercel.com/tailwindlabs/headlessui-react/62EppTRzqaq4opm6KpcizFh5fD2W
✅ Preview: https://headlessui-react-git-fix-react-transition-bug-tailwindlabs.vercel.app

headlessui-vue – ./packages/playground-vue

🔍 Inspect: https://vercel.com/tailwindlabs/headlessui-vue/DLQnivi2TVjtBHYRQVWn3fmWsPE5
✅ Preview: https://headlessui-vue-git-fix-react-transition-bug-tailwindlabs.vercel.app

@thecrypticace
Copy link
Contributor Author

I've still got to update the tests but wanted to be sure I'm not thinking about this wrong.

@mohammadzolfali
Copy link

mohammadzolfali commented Feb 19, 2022 via email

This allows us to guarantee that the ref is always referencing the
latest callback. This also allows us to re-run fewer effects because we
don't really care about intermediate callback values, just the last one.
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.

2 participants