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 flushSync warning for Combobox component with immediate prop enabled #3366

Merged
merged 3 commits into from
Jul 5, 2024

Conversation

RobinMalfait
Copy link
Member

@RobinMalfait RobinMalfait commented Jul 5, 2024

This PR fixes an issue where React shows a warning that it is not able to use flushSync while it's already rendering.

The recommended solution in that case is to move the flushSync call to a scheduler task or micro task.

The scenario where it happens in this case:

{condition && (
  <Combobox immediate>
    <ComboboxInput autoFocus />
  </Combobox>
)}

This will conditionally render the Combobox with the immediate prop (which means that it will open once the ComboboxInput receives focus). But the ComboboxInput also has the autoFocus prop which means that it will focus immediately when it's rendered.

Fixes: #3334

Copy link

vercel bot commented Jul 5, 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 Jul 5, 2024 3:29pm
headlessui-vue ✅ Ready (Inspect) Visit Preview 💬 Add feedback Jul 5, 2024 3:29pm

This will make sure that React is able to flush this correctly by delaying the call using a microTask.
Now that it's nested, let's adjust the width of the comments
@RobinMalfait RobinMalfait merged commit 5fb738f into main Jul 5, 2024
8 checks passed
@RobinMalfait RobinMalfait deleted the fix/issue-3334-3 branch July 5, 2024 15:46
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
2 participants