floating-vue icon indicating copy to clipboard operation
floating-vue copied to clipboard

Hydration issues - Nuxt 3/Vue 3

Open jawngee opened this issue 1 year ago • 11 comments

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.

jawngee avatar Dec 31 '23 10:12 jawngee

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

simba77 avatar Jan 09 '24 08:01 simba77

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 avatar Jan 11 '24 11:01 Akryum

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

Akryum avatar Jan 11 '24 11:01 Akryum

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.

jawngee avatar Jan 11 '24 11:01 jawngee

in Nuxt3 I used

<ClientOnly>
    <template #fallback>
        <Item2Render />
    </template>
    <VTooltip>
        <Item2Render />
        <template #popper>
            <PopperContent />
        </template>
    </VTooltip>
<ClientOnly>

sbittmann avatar Jan 16 '24 07:01 sbittmann

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

yoshrubin avatar Jan 16 '24 09:01 yoshrubin

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

Mini-ghost avatar Jan 16 '24 20:01 Mini-ghost

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

Hey, same issue here

Did you found a solution to that please ?

max13h avatar Feb 05 '24 22:02 max13h

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

Dodje avatar Feb 06 '24 09:02 Dodje

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 avatar Feb 19 '24 18:02 Nuzzlet

My soloution for the time being is this:

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

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

Nuzzlet avatar Mar 19 '24 16:03 Nuzzlet