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

Hydration error with scoped slots and component discovery (async components) #8904

Closed
KaragiannidesAgapios opened this issue Feb 25, 2021 · 14 comments · Fixed by vuejs/vue#11963

Comments

@KaragiannidesAgapios
Copy link

KaragiannidesAgapios commented Feb 25, 2021

Versions

  • nuxt: ^2.14.12
  • node: v14.15.4

Reproduction

Hello everyone and thank you in advance.
I have a strange issue that I don't really understand what's the problem and how to deal with it.
I have installed a fresh nuxt ssr project.
I'm getting the following warning
[Vue warn]: The client-side rendered virtual DOM tree is not matching server-rendered content. This is likely caused by incorrect HTML markup, for example nesting block-level elements inside <p>, or missing <tbody>. Bailing hydration and performing full client-side render.

I have three simple components: Form, Input, Button.
Form.vue

<template>
  <form v-bind="$attrs" class="w-full" @submit.prevent="$emit('submitted')">
    <div class="space-y-2 mb-4">
      <slot name="fields" />
    </div>
      <slot name="button" />
    </div>
  </form>
</template>
<script>
export default {
  computed: {
    hasFields() {
      return !!this.$slots.fields
    },
  },
}
</script>

Input.vue

<template>
  <div class="relative w-full">
    <input class="form-input block w-full" />
  </div>
</template>
<script>
export default {
  inheritAttrs: false,
}
</script>

Button.vue

<template>
  <button
    type="submit"
    class="relative btn inline-flex items-center justify-center transition ease-in-out duration-150"
  >
    Save
  </button>
</template>
<script>
export default {}
</script>

I use my components in pages/index.vue like this:

<template>
  <div>
    <Form>
      <template #fields>
        <Input />
        <Input />
      </template>
      <template #button>
        <Button />
      </template>
    </Form>
    <Form>
      <template #fields>
        <Input />
        <Input />
      </template>
      <template #button>
        <Button />
      </template>
    </Form>
  </div>
</template>

<script>
export default {}
</script>

If i use the Form component only once in the view i don't get the warning.
If i use it twice i get it.

Steps to reproduce

Reproduction link

  1. Install a fresh nuxt ssr project.
  2. Create the components as in the reproduction link

What is Expected?

All the components to render normally without any warnings or errors.

What is actually happening?

I get the following warning.
[Vue warn]: The client-side rendered virtual DOM tree is not matching server-rendered content. This is likely caused by incorrect HTML markup, for example nesting block-level elements inside <p>, or missing <tbody>. Bailing hydration and performing full client-side render.

Some extra notes
I know that wrapping the whole thing inside a <client-only> fixes the problem but i want to understand why is this happening in order to avoid it in future cases.
Also if I remove components: true from nuxt.config.js and import the components normally again the warning is gone

<script>
import Input from '~/components/Input'
import Button from '~/components/Button'
import Form from '~/components/Form'

export default {
  components: { Form, Button, Input}
}
</script>
Copy link
Member

danielroe commented Feb 25, 2021

Check out https://blog.lichter.io/posts/vue-hydration-error/ - hope that helps!

You may have an issue with naming your components the same as native HTML5 element names.

@danielroe danielroe reopened this Feb 25, 2021
@KaragiannidesAgapios
Copy link
Author

@danielroe Thank you for the quick response but I already tried it and it doesn't change anything.

@gpanos
Copy link

gpanos commented Feb 25, 2021

@danielroe don't know if this helps but i can reproduce the same error with non matching HTML5 element names

https://codesandbox.io/s/elegant-neumann-6h3ju?file=/pages/index.vue

@manniL
Copy link
Member

manniL commented Feb 25, 2021

Looks like that is an issue with slots in slotted components. Wondering if that's a vue-ssr-renderer thing

@gpanos
Copy link

gpanos commented Feb 26, 2021

@manniL not sure if i did it correctly but seems to be working fine the same exact code as my previous link in a plain vue cli app using vue-ssr-renderer. You can see it here https://codesandbox.io/s/ssr-vue-forked-rhoki?file=/src/App.vue
Seems that i can only reproduce it in a Nuxt application with components auto importing enabled.

@manniL
Copy link
Member

manniL commented Feb 26, 2021

Indeed. When explicitly importing the components it works as expected BTW: https://k11kl.sse.codesandbox.io/

I changed the title accordingly.

@manniL manniL changed the title The client-side rendered virtual DOM tree is not matching server-rendered content. Hydration error with slotted components and auto component discovery Feb 26, 2021
@mschoeffmann
Copy link

mschoeffmann commented Mar 4, 2021

I'm not sure if it is related to this issue, but as soon as I upgrade from Nuxt 2.14.12 to 2.15.2, I get a lot of [Vue warn]: The client-side rendered virtual DOM tree is not matching server-rendered content. This is likely caused by incorrect HTML markup, for example nesting block-level elements inside <p>, or missing <tbody>. which did not appear in 2.14.12.

Node version = 12.20.
Nuxt Target = static.

@gpanos
Copy link

gpanos commented Mar 5, 2021

@mschoeffmann this specific issue persists in both versions.

Copy link
Member

Would you be able to file an issue at https://github.com/nuxt/components/issues by chance? 🙏

@gpanos
Copy link

gpanos commented Mar 9, 2021

@danielroe nuxt/components#164

@gsjen
Copy link

gsjen commented Mar 9, 2021

This looks very similar to #6844.

@pi0 pi0 changed the title Hydration error with slotted components and auto component discovery Hydration error with scoped slots and component discovery (async components) Mar 16, 2021
@pi0
Copy link
Member

pi0 commented Mar 16, 2021

Waiting for upstream: vuejs/vue#11963

@aaronransley
Copy link
Contributor

aaronransley commented May 26, 2021

@pi0 Any chance we could get a new Nuxt release with the vue package bumped to 2.6.13? Looks like vuejs/vue#11963 resolved this issue upstream.

Edit: Apologies, I just realized that 2.6.13 is still pending release on the vue side.

@stale
Copy link

stale bot commented Jun 26, 2021

Thanks for your contribution to Nuxt!
This issue has been automatically marked as stale because it has not had recent activity. It will be closed if no further activity occurs.
If you would like this issue to remain open:

  1. Verify that you can still reproduce the issue in the latest version of nuxt-edge
  2. Comment the steps to reproduce it

Issues that are labeled as pending will not be automatically marked as stale.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging a pull request may close this issue.

8 participants