[Bug]: id contains undefined on initial render
See original GitHub issueWhat package within Headless UI are you using?
What version of that package are you using?
v1.0.0
What browser are you using?
Firefox
Reproduction repository
https://headlessui.dev/examples/react-radio-group-hero
Describe your issue
On initial render, the ids of the radio group are headlessui-radiogroup-option-undefined
. I also tested the menu component and it has the same issue.
Could this be a regression of https://github.com/tailwindlabs/headlessui/issues/110?
Issue Analytics
- State:
- Created 2 years ago
- Reactions:1
- Comments:6
Top Results From Across the Web
Watch Out for Undefined State - Dave Ceddia
When you fetch data asynchronously, the component will render at least once before that data is loaded – regardless of whether it's fetched...
Read more >Array of objects is undefined when page is rendered. Potential ...
I have to components, Parent and Child. The Parent component is passing data to the Child component via props. I can see the...
Read more >Troubleshooting common React Native bugs - LogRocket Blog
This troubleshooting guide shares how to easily find and address common React Native bugs. See common error examples.
Read more >A Guide to Common React Errors
The bug: You returned undefined, which is an invalid type for React's render method to return. ... The fix: Return a valid type:...
Read more >Screen - React Navigation
const Stack = createNativeStackNavigator(); // Stack contains Screen ... You need to provide at least a name and a component to render for...
Read more >
Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free
Top Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found
Hey all!
Doing a big GitHub cleanup. Our conversation is spread across multiple months (sorry about that!). I think that it is a good trade-off for now and we probably eventually want to fix this, but instead of fixing this ourselves, I think it would nice to use the new
useId
that React is providing.Once we are working (and relying) on React 18 (improved) support, this should hopefully fix itself.
Ah, I see from the Reach UI
useId
hook, which is also used by Headless UI, that rendering order can be nondeterministic when using React concurrent mode, so my previous assumption is wrong. They’ve heavily documented why they believe this approach is the best compromise.I think I agree with this having now understood the logic behind the
useId
hook - it results in “invalid” HTML, but it improves usability in practice since JavaScript is required for these components anyway.