vuetify icon indicating copy to clipboard operation
vuetify copied to clipboard

[Bug Report][3.6.4] id Hydration mismatch

Open kingyue737 opened this issue 1 year ago • 2 comments
trafficstars

Environment

Vuetify Version: 3.6.4 Vue Version: 3.4.25 Browsers: Edge 124.0.0.0 OS: Windows 10

Steps to reproduce

mount a vuetify component with id or similar attribute

Expected Behavior

no warning

Actual Behavior

[Vue warn]: Hydration attribute mismatch on input#input-2.v-field__input 
  - rendered on server: id="input-2"
  - expected on client: id="input-0"

[Vue warn]: Hydration attribute mismatch on div#input-2-messages.v-messages 
  - rendered on server: id="input-2-messages"
  - expected on client: id="input-0-messages"

[Vue warn]: Hydration attribute mismatch on label.v-label.v-field-label.v-field-label--floating 
  - rendered on server: for="input-2"
  - expected on client: for="input-0"

Reproduction Link

https://stackblitz.com/edit/github-fi3r47-ntgp2l

kingyue737 avatar Apr 26 '24 04:04 kingyue737

Same issue here, also with form inputs.

As I could not find any information on how to fix this, I temporarily worked around it by putting the whole v-form into a v-no-ssr directive. But it's not ideal.

frederikheld avatar May 07 '24 12:05 frederikheld

@frederikheld my temporary workaround is filtering mismatch warning via warnHandler

for example

export default defineNuxtPlugin((nuxtApp) => {
  nuxtApp.vueApp.config.warnHandler = (msg, instance, info) => {
    if (
      msg.startsWith('Hydration attribute mismatch') &&
      (msg.includes('id="input') || msg.includes('for="input'))
    ) {
      return;
    }
    console.warn(msg, info);
  };
});

kingyue737 avatar May 08 '24 04:05 kingyue737

This can be fixed by useId introduced by vue v3.5 https://blog.vuejs.org/posts/vue-3-5#useid

kingyue737 avatar Sep 05 '24 04:09 kingyue737

This can be fixed by useId introduced by vue v3.5 https://blog.vuejs.org/posts/vue-3-5#useid

Thanks! This is useful in two ways:

  • Vuetify developers can use this to fix the problem permanently.
  • I can use it to work around the issue by overriding the IDs until it's fixed in Vuetify.

rudolfbyker avatar Sep 06 '24 10:09 rudolfbyker