fix(ssr): apply ssr props to the the fallback vnode-based branch in ssr (#7247)

close #6123
This commit is contained in:
edison 2024-08-19 16:22:05 +08:00 committed by GitHub
parent ac2a410e46
commit 98b83e86d1
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
2 changed files with 24 additions and 7 deletions

View File

@ -1,5 +1,5 @@
import { createApp, createVNode } from 'vue'
import { renderToString } from '../src/renderToString'
import { renderToString } from '../src'
describe('ssr: dynamic component', () => {
test('resolved to component', async () => {
@ -17,6 +17,23 @@ describe('ssr: dynamic component', () => {
).toBe(`<div><!--[--><span>slot</span><!--]--></div>`)
})
test('resolved to component with v-show', async () => {
expect(
await renderToString(
createApp({
components: {
one: {
template: `<component is="div"><slot/></component>`,
},
},
template: `<one><one v-show="false">hi</one></one>`,
}),
),
).toBe(
`<div><!--[--><div style=\"display:none;\"><!--[-->hi<!--]--></div><!--]--></div>`,
)
})
test('resolve to element', async () => {
expect(
await renderToString(

View File

@ -217,7 +217,11 @@ export function renderVNode(
parentComponent: ComponentInternalInstance,
slotScopeId?: string,
): void {
const { type, shapeFlag, children } = vnode
const { type, shapeFlag, children, dirs, props } = vnode
if (dirs) {
vnode.props = applySSRDirectives(vnode, props, dirs)
}
switch (type) {
case Text:
push(escapeHtml(children as string))
@ -283,13 +287,9 @@ function renderElementVNode(
slotScopeId?: string,
) {
const tag = vnode.type as string
let { props, children, shapeFlag, scopeId, dirs } = vnode
let { props, children, shapeFlag, scopeId } = vnode
let openTag = `<${tag}`
if (dirs) {
props = applySSRDirectives(vnode, props, dirs)
}
if (props) {
openTag += ssrRenderAttrs(props, tag)
}