-
-
Notifications
You must be signed in to change notification settings - Fork 8.4k
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
v-html on <component>
does not work in SSR
#12520
Comments
Similar to #6553 |
Well, I really need to use <template>
<component
:is="isBlockMath ? 'div' : 'span'"
:class="[$style.math, isBlockMath ? $style.blockMath : $style.inlineMath, meta.freeze && $style.freeze]"
v-html="mathHtml"
v-once />
</template> The workaround is using <template>
<div v-if="isBlockMath" v-html="mathHtml" :class="classes" v-once></div>
<span v-else v-html="mathHtml" :class="classes" v-once></span>
</template> And if using So there is simply nothing to discuss here, as I see it... |
@Gwynerva |
@edison1105 Thank you. Yeah I think this will do. But still as I already said |
I think using v-html or v-text on a component(or dynamic component) is somewhat of an anti-pattern, not sure if it will be supported, Let's wait for Evan's input. |
As the use case doesn’t involve custom components, I think it’s legit for dynamic element tags. |
Of course I am talking about "vanilla" HTML tags. Can't think of why someone would need to |
Tried to use render function <script setup>
import { h } from 'vue';
const isBlock = true;
const MyNode = h(isBlock ? 'div' : 'span', { innerHTML: '<strong>Hello World!</strong>' });
</script>
<template>
<MyNode />
</template> I am not sure but I think this might be the same bug. UPDATE: Turns out when using setup syntax <script setup>
import { h } from 'vue';
const MyNode = h('div', { innerHTML: '<strong>Hello World!</strong>' });
</script>
<template>
<MyNode />
</template> |
To sum up, there are two bugs, both working just fine in normal Vue and not working in Vue SSR:
It was pointed out that second bug needs discussion, but the first one I think obviously is an SSR bug. What is even worse, the first bug actually prevents a simple possible workaround to avoid using @danielroe I think it would be better to rename issue to something like "Dynamic tag generation fails in SSR" to address both problems in one issue. @yyx990803 Would be really cool to see both or at least the first one to be fixed. Because right now the only way is to duplicate tags directly in |
This is considered an edge case. IMO, a VNode cannot be rendered directly, at least, it should be |
I'm a relative newcomer to Vue but isn't And if so, what is wrong (besides loosing reactivity) about rendering vnode directly via UPDATE: I tried rendering <script lang="ts" setup>
// ...
const Tag = h(props.isBlockMath ? 'div' : 'span', { innerHTML: props.html });
</script>
<template>
<component :is="Tag" :class="classes" v-once />
</template> Finally, the workaround without creating sub-Vue files. <script lang="ts" setup>
// ...
const Tag = h(props.isBlockMath ? 'div' : 'span', { innerHTML: props.html });
</script>
<template>
<!-- Works -->
<component :is="Tag" :class="classes" v-once />
<!-- Fails -->
<component :is="isBlockMath ? 'div' : 'span'" :class="classes" v-html="html" v-once />
<!-- Also Fails -->
<component :is="isBlockMath ? h('div') : h('span')" :class="classes" v-html="html" v-once />
</template> |
@Gwynerva |
@Ghosterbeef It does not work when writing Still need a comment from @edison1105 or @yyx990803. I think it should work with both |
@Gwynerva no its not. If component :is="Tag" is not wrapped in a parent tag and is not its only child, a hydration error occurs |
@Ghosterbeef provide a link to an example in Vue SFC Playground then (there is a "share" button at top right corner). Because I can't reproduce it and everything works fine on my setup. |
Yeah now I see. Really weird stuff is happening with SSR... |
if the Nested |
@Ghosterbeef turns out it's a |
Vue version
3.5.13
Link to minimal reproduction
https://play.vuejs.org/#__PROD____SSR__eNp9kcFPgzAUxv+V+i67TIhBLwSXqFniPGzGcWxiEJ7QWVrSFiRZ+N9tC8MdliU9vHy/r33fez3CU9MEXYsQQ2KwbnhmcEUFIUnBOl9MZVoxTezpmGZfHJPwjOeybqRAYUjM9COFhWULCqS7rUzNnZBoo6QoV+nrZk/s2e7SmyScRGcNx6bTq0k4Z4ElGJ1L8c3K4KClsEGPzkrBdWUc1a4xTApNISaeOJZxLn/fvGZUi8uTnleY/1zQD7p3GoV3hRpVhxRmZjJVohnxer/F3tYzrGXRcuu+Aj9QS966jKPtuRWFjX3m82k3dofKMFGmet0bFPo0lAvqnIP3U7C/9XJl9P+4UXDv71Ex2C1+dqjcm3aBUfAQ3EUw/AFR/qMz
Steps to reproduce
What is expected?
The
<component>
should render in both SSR + client-onlyWhat is actually happening?
THIS IS NOT
is not rendered in SSR.System Info
No response
Any additional comments?
reported in nuxt/nuxt#30202
The text was updated successfully, but these errors were encountered: