Skip to content

Commit 98b83e8

Browse files
authored
fix(ssr): apply ssr props to the the fallback vnode-based branch in ssr (#7247)
close #6123
1 parent ac2a410 commit 98b83e8

File tree

2 files changed

+24
-7
lines changed

2 files changed

+24
-7
lines changed

Diff for: packages/server-renderer/__tests__/ssrDynamicComponent.spec.ts

+18-1
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
import { createApp, createVNode } from 'vue'
2-
import { renderToString } from '../src/renderToString'
2+
import { renderToString } from '../src'
33

44
describe('ssr: dynamic component', () => {
55
test('resolved to component', async () => {
@@ -17,6 +17,23 @@ describe('ssr: dynamic component', () => {
1717
).toBe(`<div><!--[--><span>slot</span><!--]--></div>`)
1818
})
1919

20+
test('resolved to component with v-show', async () => {
21+
expect(
22+
await renderToString(
23+
createApp({
24+
components: {
25+
one: {
26+
template: `<component is="div"><slot/></component>`,
27+
},
28+
},
29+
template: `<one><one v-show="false">hi</one></one>`,
30+
}),
31+
),
32+
).toBe(
33+
`<div><!--[--><div style=\"display:none;\"><!--[-->hi<!--]--></div><!--]--></div>`,
34+
)
35+
})
36+
2037
test('resolve to element', async () => {
2138
expect(
2239
await renderToString(

Diff for: packages/server-renderer/src/render.ts

+6-6
Original file line numberDiff line numberDiff line change
@@ -217,7 +217,11 @@ export function renderVNode(
217217
parentComponent: ComponentInternalInstance,
218218
slotScopeId?: string,
219219
): void {
220-
const { type, shapeFlag, children } = vnode
220+
const { type, shapeFlag, children, dirs, props } = vnode
221+
if (dirs) {
222+
vnode.props = applySSRDirectives(vnode, props, dirs)
223+
}
224+
221225
switch (type) {
222226
case Text:
223227
push(escapeHtml(children as string))
@@ -283,13 +287,9 @@ function renderElementVNode(
283287
slotScopeId?: string,
284288
) {
285289
const tag = vnode.type as string
286-
let { props, children, shapeFlag, scopeId, dirs } = vnode
290+
let { props, children, shapeFlag, scopeId } = vnode
287291
let openTag = `<${tag}`
288292

289-
if (dirs) {
290-
props = applySSRDirectives(vnode, props, dirs)
291-
}
292-
293293
if (props) {
294294
openTag += ssrRenderAttrs(props, tag)
295295
}

0 commit comments

Comments
 (0)