Skip to content

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
@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
Development

Successfully merging this pull request may close these issues.

React warning flushSync was called from inside a lifecycle method when conditionally displaying an immediate and autofocused combobox
2 participants