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

SSR Hydration errors stemming from v-bind in CSS coupled with child component style bindings #11735

Closed
adamdehaven opened this issue Aug 28, 2024 · 3 comments · Fixed by #11739
Labels
🔨 p3-minor-bug Priority 3: this fixes a bug, but is an edge case that only affects very specific usage. scope: sfc-style-vars

Comments

@adamdehaven
Copy link

adamdehaven commented Aug 28, 2024

Vue version

3.4.38

Link to minimal reproduction

Vue SFC Playground Reproduction

Steps to reproduce

Load the playground reproduction, and ensure SSR is enabled. You'll see the Hydration Error warning in the console.

Code Example

Note

This is the same code submitted in the reproduction

Click to view the code from the reproduction
// App.vue
<script setup>
import ComponentTest from './ComponentTest.vue'

const props = defineProps({
  backgroundColor: {
    type: String,
    default: 'blue'
  },
  padding: {
    type: String,
    default: '20px'
  }
})
</script>

<template>
  <ComponentTest class="parent-component">
    <div class="child-content">
      Hello 👋
    </div>
  </ComponentTest>
</template>

<style scoped>
.parent-component {
  background-color: v-bind('props.backgroundColor')
}

.child-content {
  color: #fff;
  padding: v-bind('props.padding')
}
</style>
// ComponentTest.vue
<template>
  <div :style="{ display }">
    <slot name="default" />
  </div>
</template>

<script setup lang="ts">
defineProps({
  display: {
    type: String,
    default: 'flex',
  }
})
</script>

What is expected?

The inline style bindings in the child component would be resolved properly during SSR to prevent hydration errors.

What is actually happening?

The style bindings are not being properly merged, triggering a hydration error in SSR

System Info

No response

Any additional comments?

Essentially, the problem occurs when you use v-bind in a parent component (which under the hood inlines CSS custom properties on the root of the child component) and then you ALSO have bound dynamic styles to the root element internally.

@edison1105 edison1105 added 🔨 p3-minor-bug Priority 3: this fixes a bug, but is an edge case that only affects very specific usage. scope: sfc-style-vars labels Aug 29, 2024
@adamdehaven
Copy link
Author

adamdehaven commented Aug 29, 2024

a side note: this only happens in DEV.

This could be correct; however, I’m not 100% sure.

With a more complicated example, I see some properties are totally omitted; it’s not just the difference in slashes.

IMG_7319

@edison1105
Copy link
Member

a side note: this only happens in DEV.

This could be correct; however, I’m not 100% sure. With a more complicated example, I see some properties are totally omitted; it’s not just the difference in slashes

I've made a PR to fix this issue. You can try using these temporary packages to see if they solve all your issues. If they don’t, please continue to provide feedback.

@adamdehaven
Copy link
Author

adamdehaven commented Aug 29, 2024

Ah yep I just noticed the linked PR after I submitted the comment.

@github-actions github-actions bot locked and limited conversation to collaborators Sep 19, 2024
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
🔨 p3-minor-bug Priority 3: this fixes a bug, but is an edge case that only affects very specific usage. scope: sfc-style-vars
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants