Akryum / floating-vue

💬 Easy tooltips, popovers, dropdown, menus... for Vue
https://floating-vue.starpad.dev/
MIT License
3.33k stars 338 forks source link

Hydration issues - Nuxt 3/Vue 3 #1006

Open jawngee opened 10 months ago

jawngee commented 10 months ago

This just started showing up in the latest Nuxt 3.9, probably due to the Vue version bump but I'm not sure.

Getting a lot of Hydration attribute mismatch because the ID of the popper is different from SSR. Errors look like:

- rendered on server: id=\"popper_44tr48ae_tdggwc\"
- expected on client: id=\"popper_gjw3s4ml_tdglzw\"
  Note: this mismatch is check-only. The DOM will not be rectified in production due to performance overhead.

Not sure how to solve this or if it has any real impact at all.

simba77 commented 10 months ago

As a temporary solution, you can add the aria-id attribute <v-dropdown aria-id="some-dropdown">

Akryum commented 10 months ago

Yes you can use ariaId prop to prevent using a random id for the aria-describedby attribute. Maybe it could be fixed in nuxt via the module but I'm not sure.

Akryum commented 10 months ago

Also is this caused by popper that are already open when they are rendered on the server? For example with :shown="true"

jawngee commented 10 months ago

Thanks, I will give the aria thing a try.

No, they aren't opened but let me double check that t confirm.

On Jan 11, 2024, at 6:09 PM, Guillaume Chau @.***> wrote:

Also is this caused by popper that are already open when they are rendered on the server? For example with :shown="true"

— Reply to this email directly, view it on GitHub https://github.com/Akryum/floating-vue/issues/1006#issuecomment-1886900778, or unsubscribe https://github.com/notifications/unsubscribe-auth/AAAK3ILITTJDSC6KWYMWSMTYN7B6ZAVCNFSM6AAAAABBIFQFEKVHI2DSMVQWIX3LMV43OSLTON2WKQ3PNVWWK3TUHMYTQOBWHEYDANZXHA. You are receiving this because you authored the thread.

sbittmann commented 10 months ago

in Nuxt3 I used

<ClientOnly>
    <template #fallback>
        <Item2Render />
    </template>
    <VTooltip>
        <Item2Render />
        <template #popper>
            <PopperContent />
        </template>
    </VTooltip>
<ClientOnly>
yoshrubin commented 10 months ago

the above works for the ariaId issue but I am getting

 - rendered on server: tabindex=""
  - expected on client: tabindex="0"
  Note: this mismatch is check-only. The DOM will not be rectified in production due to performance overhead.
  You should fix the source of the mismatch. 
  at <VPopperContent ref="popperContent" popper-id="dropdown" theme="info-dropdown"  ... > 
  at <Popper ref="popper" theme="info-dropdown" referenceNode=null  ... > 
  at <Dropdown triggers= ['click'] skidding=-30 distance=25 > 

when using a Dropdown so the contents of the Popper are clickable

Mini-ghost commented 10 months ago

Yes you can use ariaId prop to prevent using a random id for the aria-describedby attribute. Maybe it could be fixed in nuxt via the module but I'm not sure.

This was useful for me, but it might not be the best approach as it causes the vuejs-accessibility's aria-props to throw errors at me. I wonder if there's another way to address this?

eslint-disable vuejs-accessibility/aria-props
Dodje commented 9 months ago

I believe it's not a very good thing to generate id for every tooltip and dropdown manually..

Nuzzlet commented 9 months ago

Headless UI solved this problem with the new UseID function in Nuxt This solution uses Nuxt's new UseID composable to generate an SSR safe ID. The warning is caused by the latest version of Nuxt which improved hydration mismatch detection.

Nuzzlet commented 8 months ago

My soloution for the time being is this:

<script setup>
    const ariaId = useId()
</script>

<template>
    <VDropdown :aria-id="ariaId"  />
</template>