nuxt / ui

A UI Library for Modern Web Apps, powered by Vue & Tailwind CSS.
https://ui.nuxt.com
MIT License
4.05k stars 512 forks source link

Hydration attribute mismatch after update Nuxt to v3.9.0 #1171

Closed ivan-mihalic closed 9 months ago

ivan-mihalic commented 10 months ago

Environment

Version

v2.11.1

Reproduction

https://stackblitz.com/edit/nuxt-starter-5tmfpt?file=components%2FUserForm.vue

Description

Hi guys, I updated Nuxt to version 3.9.0 and I am getting Hydration attribute mismatch for example on USelectMenu or UDropdown viz screenshot. I think it is a bug and it is now showing after improve ssr hydration mismatch checks in Vue 3.4.

CleanShot 2023-12-29 at 17 38 06@2x

Additional context

No response

Logs

No response

MickL commented 10 months ago

I do have the same issue

hoanghadu commented 10 months ago

I have the same issue

ellellie commented 10 months ago

Also occurring with UCheckbox, here's a minimal reproduction (app.vue):

<template>
  <UCheckbox v-model="state" label="Test checkbox" />
</template>

<script setup lang="ts">
const state = ref(true)
</script>

Notably does not occur when the ref is false.

Testing against 2.11.1 and 7151b7b97d42f389506521044ebaffa8a299e7fb with nuxt@3.9.0 both yield the same result. image

pixelpaulaus commented 10 months ago

getting same things now after the update

tabuz commented 10 months ago

I also got plenty of hydration mismatch after upgrade.

fishDev94 commented 10 months ago

same bug but without info after upgrade to 3.9.0 I tried with --no-force and --force and i have the same issue

Screenshot 2024-01-02 at 15 09 50
ahoiroman commented 10 months ago

Same here with ui-pro/landing template

benjamincanac commented 10 months ago

I think this is due to latest vue 3.4, we have to override all of Headless UI generated ids with the future useId composable from Nuxt: https://github.com/nuxt/nuxt/pull/23368 but it hasn't been released yet.

In the meantime, can you try to set the resolution to vue to 3.3.13?

yoricktran commented 10 months ago

I think this is due to latest vue 3.4, we have to override all of Headless UI generated ids with the future useId composable from Nuxt: nuxt/nuxt#23368 but it hasn't been released yet.

In the meantime, can you try to set the resolution to vue to 3.3.13?

3.3.13 fixed it for me for now, thanks!

whcxxb commented 10 months ago

Nuxt3.9.1 still has this problem and 3.3.13 can solve it

tabuz commented 10 months ago

Sorry for anoob question, but how did you achieved to pin vue@3.3.13?

My package.json looks like below

{
  "private": true,
  "scripts": {
    "build": "nuxt build",
    "dev": "nuxt dev",
    "generate": "nuxt generate",
    "preview": "nuxt preview",
    "postinstall": "nuxt prepare"
  },
  "dependencies": {
    "@nuxt/ui": "^2.11.0",
    "@nuxtjs/google-fonts": "^3.1.0",
    "@pinia/nuxt": "^0.5.1",
    "consola": "^3.2.3",
    "nuxt-proxy": "^0.4.1",
    "pinia": "^2.1.7",
    "sass": "^1.69.5",
    "vue": "^3.3.9",
    "zod": "^3.22.4"
  },
  "devDependencies": {
    "@iconify/vue": "^4.1.1",
    "@nuxt/devtools": "^1.0.3",
    "@nuxtjs/i18n": "^8.0.0-rc.5",
    "@vueuse/core": "^10.6.1",
    "@vueuse/nuxt": "^10.6.1",
    "nuxt": "^3.9.0",
    "prettier": "^3.1.0",
    "prettier-plugin-tailwindcss": "^0.5.7"
  }
}
benjamincanac commented 10 months ago

You need to set it in resolutions:

{
  "private": true,
  "scripts": {
    "build": "nuxt build",
    "dev": "nuxt dev",
    "generate": "nuxt generate",
    "preview": "nuxt preview",
    "postinstall": "nuxt prepare"
  },
  "dependencies": {
    "@nuxt/ui": "^2.11.0",
    "@nuxtjs/google-fonts": "^3.1.0",
    "@pinia/nuxt": "^0.5.1",
    "consola": "^3.2.3",
    "nuxt-proxy": "^0.4.1",
    "pinia": "^2.1.7",
    "sass": "^1.69.5",
    "vue": "^3.3.9",
    "zod": "^3.22.4"
  },
  "devDependencies": {
    "@iconify/vue": "^4.1.1",
    "@nuxt/devtools": "^1.0.3",
    "@nuxtjs/i18n": "^8.0.0-rc.5",
    "@vueuse/core": "^10.6.1",
    "@vueuse/nuxt": "^10.6.1",
    "nuxt": "^3.9.0",
    "prettier": "^3.1.0",
    "prettier-plugin-tailwindcss": "^0.5.7"
  },
  "resolutions": {
    "vue": "3.3.13"
  }
}
tabuz commented 10 months ago

@benjamincanac Thank you for quick reply. I've tried what you suggested and while executing npm list vue is shows as vue@3.4.5 deduped everywhere and app itself still throws hydration mismatch.

npm package.json docs doesnt mention usage of keyword resolutions. Should I use this package https://www.npmjs.com/package/npm-force-resolutions ?

benjamincanac commented 10 months ago

Oh sorry, this is for yarn and pnpm. It seems you can use overrides with npm since 8.3.0.

lammerfalcon commented 10 months ago

i have the same issue with UTable - hydration mistmaches - warning on UCheckbox inside table component really dont want to downgrade versions(( any info when we can get update?

dolbex commented 10 months ago

This seems related as well. See the following reproduction:

https://stackblitz.com/edit/nuxt-starter-t3xebe?file=components%2FAttributeTest.vue

I have a form with a dynamic action attribute. I even understand the hydration attr mismatch but why is the value wrong on initial load. It should have loaded with "something" and then changed to the clientside date/time. It can change based on the button click. This was unexpected for us.

RomanSkrypnik commented 10 months ago

I'm facing the same issue

sync42johnny commented 10 months ago

i do have the same issue -\^-^/-

jontybrook commented 10 months ago

Ditto here.. causing all sorts of mismatches with a whole bunch of deps (headless, radix, etc etc). Think the best fix is upstream in vue?

I'm using Bun, which supports both the overrides and resolutions syntax. So the temporary solution for me is in package.json:

"overrides": { "vue": "3.3.13" },

lt0216 commented 10 months ago

Nuxt3.9.1仍然有这个问题,3.3.13可以解决

所以是要降低版本来解决这个问题吗

lt0216 commented 10 months ago

同样发生在UCheckbox,这里是一个最小的复制(app.vue):

<template>
  <UCheckbox v-model="state" label="Test checkbox" />
</template>

<script setup lang="ts">
const state = ref(true)
</script>

值得注意的是,当 ref 为 false 时不会发生。

针对 2.11.1 和7151b7b进行的测试均nuxt@3.9.0产生相同的结果。 图像

问题解决了吗

benjamincanac commented 9 months ago

It seems Vue will have its own useId composable in 3.5: https://twitter.com/youyuxi/status/1745379112456429688.

cco3 commented 9 months ago

I get the sense you all already understand the root issue, but sense I haven't seen anyone mention it, I'm also seeing this with UTabs.

joeldegerman99 commented 9 months ago

I have the same issue with UDropdown

iyefreedy commented 9 months ago

I have the same issue with UDropdown

Nuxt Version: 3.9.3 Nuxt UI Version: 2.11.1 image

marcobax commented 9 months ago

The same issue occurs with Popoverbutton too

Nuxt Version: 3.9.3 Headlessui UI Version: 1.7.16

Screenshot 2024-01-25 at 19 03 16
benjamincanac commented 9 months ago

Those warnings will appear for the all components using Headless UI underneath. The only fix for now is to pin vue to 3.3.13 while waiting for Vue 3.5 and its useId composable.

Those hydration issues were already present but only displayed since Vue 3.4.

zacwebb commented 9 months ago

Nuxt has shipped a useId composable in 3.10.0 👀

ybw0014 commented 9 months ago

https://github.com/nuxt/ui/pull/1211

abyshake-anand commented 9 months ago

Seeing the same issue... Using UDropdown

"resolutions": { "vue": "3.3.13" }

pedrodruviaro commented 9 months ago

Same issue with a lot of NuxtUi componentes... even with the "resolutions" option

madebyfabian commented 9 months ago

Even after overriding, these issues still persist. Not sure if I've done it right though. I am using pnpm- Tested overrides, resolutions and pnpm.overrides

dandonovan78 commented 8 months ago

I had a bit of trouble overriding the version with npm, causing some dependency issues. After some fiddling, adding an override specifically for nuxt seems to work to set the vue version to 3.3.13 and also eliminates the hydration mismatch errors:

"overrides": {
    "nuxt": {
      "vue": "3.3.13"
    },
  },
Poraksis commented 8 months ago

"dependencies": { "flowbite": "^2.2.1", "nuxt": "^3.10.1", "vue": "^3.4.15", "vue-router": "^4.2.5" }

i have so much hydration mismatch errors so just removed nuxt ui kit, any suggestion ?

benjamincanac commented 8 months ago

@Poraksis There are already tons of comments in this issue answering that already: https://github.com/nuxt/ui/issues/1171#issuecomment-1910975705

This issue has already been solved and will be released this week in v2.14.0.

m0k99 commented 8 months ago

I have the same issue

benjamincanac commented 8 months ago

@m0k99 Do you still encounter this issue with https://github.com/nuxt/ui/releases/tag/v2.14.0?

m0k99 commented 8 months ago

@m0k99 Do you still encounter this issue with https://github.com/nuxt/ui/releases/tag/v2.14.0? in my project, I don't use NuxtUI and I write randomId in utils and use that in my component and get the following error:

Screenshot from 2024-02-24 19-22-55

cco3 commented 8 months ago

I don't use NuxtUI

This issue is about NuxtUI. If you are getting hydration mismatches without NuxtUI, it's a different problem.

I write randomId in utils

If you use a random ID in your component, what is generated on the server will differ from what's generated in the client. Naturally, you will have a hydration mismatch. You can fix this by not using a random ID.

Muslihiddin commented 7 months ago

I'm getting this warning on checkbox, but only when I reload page and checkbox is used on that page. And

    "resolutions": {
        "vue": "3.3.13"
    } 

didn't help either

noook commented 7 months ago

I think checkboxes have been fixed recently and not released yet

https://github.com/nuxt/ui/pull/1495

pixelpaulaus commented 6 months ago

Hmmm, though this was fixed in v2.14.0, but am I mistaken? As I seem to be getting the same errors on UI Buttons with the following versions...

├── @headlessui/vue@1.7.20 ├── @heroicons/vue@2.1.3 ├── @nuxt/devtools@1.2.0 ├── @nuxt/eslint-config@0.2.0 ├── @nuxt/image@1.6.0 ├── @nuxt/ui@2.15.2 ├── @nuxtjs/tailwindcss@6.12.0 ├── @pinia/nuxt@0.5.1 ├── @silvermine/videojs-quality-selector@1.3.1 ├── eslint-plugin-tailwindcss@3.15.1 ├── eslint@8.57.0 ├── file-saver@2.0.5 ├── nuxt-delay-hydration@1.3.3 ├── nuxt@3.11.2 ├── pinia@2.1.7 ├── rollup-plugin-cleanup@3.2.1 ├── sass@1.75.0 ├── unhead@1.9.7 ├── video.js@8.10.0 ├── vite-plugin-string-replace@1.1.2 ├── vue-eslint-parser@9.4.2 ├── vue-router@4.3.2 ├── vue@3.4.25 └── yup@1.4.0

lafllamme commented 3 months ago

Any updates on this? Keep getting hydration issues for <USelectMenu> and <UInput>.

Package json:

{
  "name": "nuxt-app",
  "private": true,
  "type": "module",
  "scripts": {
    "build": "nuxt build",
    "dev": "nuxt dev",
    "generate": "nuxt generate",
    "preview": "nuxt preview",
    "prepare": "nuxt prepare",
    "playwright": "pnpm exec playwright install && pnpm exec playwright install-deps",
    "postinstall": "npm run prepare"
  },
  "dependencies": {
    "@nuxt/image": "^1.7.0",
    "@nuxt/ui": "^2.17.0",
    "@pinia/nuxt": "^0.5.1",
    "@sparticuz/chromium": "^126.0.0",
    "@unocss/reset": "^0.58.9",
    "axios": "^1.7.2",
    "chromium": "^3.0.3",
    "jsdom": "^24.1.0",
    "nuxt": "^3.12.2",
    "nuxt-viewport": "^2.1.5",
    "pinia": "^2.1.7",
    "playwright": "^1.45.2",
    "std-env": "^3.7.0",
    "vue": "^3.4.31",
    "vue-router": "^4.4.0"
  },
  "devDependencies": {
    "@iconify-json/ph": "^1.1.13",
    "@nuxtjs/supabase": "^1.2.2",
    "@types/jsdom": "^21.1.7",
    "@unocss/nuxt": "^0.58.9",
    "@unocss/preset-icons": "^0.58.9",
    "@unocss/preset-web-fonts": "^0.58.9",
    "@zadigetvoltaire/nuxt-gtm": "^0.0.13",
    "sass": "^1.77.6"
  }
}

Message:

[Vue warn]: Hydration attribute mismatch on 
<button class="relative w-full disabled…-400 dark:text-gray-500" type="button"> 
  - rendered on server: (not rendered)
  - expected on client: disabled="true"
  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 <ComboboxButton ref="trigger" as="div" role="button"  ... > 
  at <Combobox by=undefined name=undefined model-value=null  ... > 
  at <SelectMenu ref="chapterMenu" option-attribute="name" value-attribute="name" 
benjamincanac commented 3 months ago

@lafllamme This issue should have been fixed a long time ago. Please open a new one with a reproduction.