Skip to content

Commit

Permalink
fix(ssr): apply ssr props to the the fallback vnode-based branch in s…
Browse files Browse the repository at this point in the history
…sr (#7247)

close #6123
  • Loading branch information
edison1105 authored Aug 19, 2024
1 parent ac2a410 commit 98b83e8
Show file tree
Hide file tree
Showing 2 changed files with 24 additions and 7 deletions.
19 changes: 18 additions & 1 deletion packages/server-renderer/__tests__/ssrDynamicComponent.spec.ts
Original file line number Diff line number Diff line change
@@ -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 () => {
Expand All @@ -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(
Expand Down
12 changes: 6 additions & 6 deletions packages/server-renderer/src/render.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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))
Expand Down Expand Up @@ -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)
}
Expand Down

0 comments on commit 98b83e8

Please sign in to comment.