Headlessui mismatch
any idea on how to solve this error? I'm using headless Disclosure, even when passing a
id
to it like
<DisclosureButton id="foo"
, I still get the hydration error with the same message15 Replies
Are you using SSR-safe id’s for headless? E.g.
provideUseId(() => useId())
shouldn't using a hardcoded id (in my case
made-to-measure
from the sc above) be SSR safe?
no idea where those headless generated ids are coming from, since I already have my own id.The generated id's come from a headlessui internal function that just increments a variable.
they should'nt be there tho if i'm passing the id?
No, the id prop you provide is not the same as the generated id used by the state stored in the components context. The generated id therefore is different for server and client in this instance.
when I inspect the DOM i don't see any elements that has either of those ids
as u can see in my screenshot
the final id is
made-to-measure
but the warning says otherwiseThat's because you're inspecting the DOM. The state is injected, the generated id used is stored there
what should I do to fix it?
The id you use, is then set on the client
Put this in your
app.vue
:
thanks,
provideHeadlessUseId
seems to work
is this mentionned somehwere?But also note that Nuxt's
useId
only works for single root elements. So the documentation shows:
You should change to:
It's actually provideUseId
, the provideHeadlessUseId
is an alias offered by the nuxt-headlessui
module.it's what I'm using and was autoimported for me
should I use
provideUseId
instead?No, what your doing is better because of the auto-import. I didn't realise you were using the module.
FYI https://github.com/P4sca1/nuxt-headlessui/issues/40
thanks!