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

Problem in Vue / Nuxt - Hydration Children Mismatch #1494

Closed
bllchmbrs opened this issue Aug 22, 2023 · 4 comments
Closed

Problem in Vue / Nuxt - Hydration Children Mismatch #1494

bllchmbrs opened this issue Aug 22, 2023 · 4 comments
Assignees

Comments

@bllchmbrs
Copy link

bllchmbrs commented Aug 22, 2023

What component (if applicable)

Describe the bug

To Reproduce
Steps to reproduce the behavior:

I receive the following warning when opening a page with this navigation component.

chunk-BVQHDTV7.js:1449 [Vue warn]: Hydration children mismatch in <div>: server rendered element contains fewer child nodes than client vdom. 
  at <Portal> 
  at <ForcePortalRoot force=true > 
  at <Dialog as="div" class="lg:hidden" onClose=fn  ... > 
  at <Navigation> 
  at <Default ref=Ref< undefined > > 
  at <LayoutLoader key="default" layoutProps= {ref: RefImpl} name="default" > 
  at <NuxtLayoutProvider layoutProps= {ref: RefImpl} key="default" name="default"  ... > 
  at <NuxtLayout> 
  at <App key=3 > 
  at <NuxtRoot>

On initial page loadWhen clicked it throws the following error:

Uncaught (in promise) TypeError: Cannot read properties of null (reading 'parentNode')
    at remove (chunk-BVQHDTV7.js:9137:26)
    at Object.remove (chunk-BVQHDTV7.js:7982:7)
    at unmount (chunk-BVQHDTV7.js:7603:20)
    at unmountComponent (chunk-BVQHDTV7.js:7692:7)
    at unmount (chunk-BVQHDTV7.js:7593:7)
    at unmountChildren (chunk-BVQHDTV7.js:7712:7)
    at unmount (chunk-BVQHDTV7.js:7621:9)
    at unmountComponent (chunk-BVQHDTV7.js:7692:7)
    at unmount (chunk-BVQHDTV7.js:7593:7)
    at unmountComponent (chunk-BVQHDTV7.js:7692:7)

Interestingly, if I comment out this code:

<Dialog as="div" class="lg:hidden" @close="mobileMenuOpen = false" :open="mobileMenuOpen"....
...
</Dialog> 

The main menu works fine (but obviously the mobile menu doesn't).

Expected behavior
I would expect it to not throw any errors.

Screenshots
If applicable, add screenshots to help explain your problem.

Browser/Device (if applicable)

  • OS: Mac
  • Browser Chrome
  • Version 115.0.5790.170
"vue": "^3.3.4"
"nuxt": "^3.6.5",

Additional context

On second thought: On second thought, this might be a problem with the dialog in headlessui. Since if I comment out that code, it works fine.

On third thought: This is a global problem with all header components in tailwindui. I cannot use any of the headers provided by tailwindui because of this. Can you all please prioritize fixing this? it's a pretty critical issue (either here or in headless ui) because it renders these components incomplete. If it is a headless ui bug, please tell me where to post it.

@reinink reinink self-assigned this Aug 23, 2023
@reinink
Copy link
Member

reinink commented Aug 23, 2023

Hey! Thanks for bringing this to our attention. You're correct, this is an issue with the <Dialog> component in Headless UI — it is not SSR compatible. That's because it uses portals. Here is a related issue about this same problem: tailwindlabs/headlessui#1496

The simple workaround here is to wrap your dialog in a <ClientOnly> component:

<ClientOnly>
  <Dialog as="div" class="lg:hidden" @close="mobileMenuOpen = false" :open="mobileMenuOpen">
    <!-- ... -->
  </Dialog>
</ClientOnly>

That said, we are going to have a look and see if there is anything we can do in Headless UI to prevent this SSR warning from happening. I'll report back once I know more 👍

@reinink
Copy link
Member

reinink commented Aug 24, 2023

Hey! Just an update here. We made some changes to Headless UI today that should fix this issue without the need for using the <ClientOnly> component. You can find that fix here: tailwindlabs/headlessui#2700

While we haven't done a new release yet, you can install this version already using our insiders channel:

npm install @headlessui/vue@insiders

Again, that should fix things for you, but let us know if not!

@reinink reinink closed this as completed Aug 24, 2023
@bllchmbrs
Copy link
Author

Sweet! Thanks, will test this out today and see how it goes!!!

@alfredlua
Copy link

Using @headlessui/vue@insiders fixed the issue for me. Thanks, @reinink!

Thanks @bllchmbrs for bringing this up too. I was stuck on this for quite a while.

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

No branches or pull requests

3 participants