Subscribe on changes!

SSR/Hydration: Re-Render due to hydration mismatch creates inconsistent DOM - textContent updated correctly, class attr isn't.

avatar
Dec 6th 2021

Version

3.2.23

Reproduction link

github.com

Steps to reproduce

  • step 1
yarn && yarn dev

What is expected?

Class and text values are the same.

What is actually happening?

img1

img2


<template>
  <div :class="color">
    {{ color }}
  </div>
</template>

<script lang="ts" setup>
import { computed } from "vue";

console.log(process.client);

const color = computed(() => {
  return process.client ? "black" : "red";
});
</script>

<style>
.red {
  color: red;
}
.black {
  color: black;
}
</style>
avatar
Dec 6th 2021

@posva

avatar
Dec 6th 2021

Seems we have a bug here when bailing out of hydration because of a mismatch - the text content was updated, but the class attribute wasn't.

avatar
Dec 6th 2021

@loyep Even though yes, this is a bug - your usage of a computed here is wrong, too.

Looking at the console, you can see that it causes a hydration mismatch.

avatar
Dec 6th 2021

Yes, I know. Only in this way can we reproduce this problem quickly.

avatar
Dec 6th 2021

LinusBorg

Not only class, but also style attributes