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

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

Merged
merged 13 commits into from
Aug 19, 2024
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'
Copy link
Member Author

@edison1105 edison1105 Feb 23, 2023

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

this change ensure initDirectivesForSSR() is called in test.


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
5 changes: 4 additions & 1 deletion packages/server-renderer/src/render.ts
Original file line number Diff line number Diff line change
Expand Up @@ -218,7 +218,10 @@ export function renderVNode(
parentComponent: ComponentInternalInstance,
slotScopeId?: string
) {
const { type, shapeFlag, children } = vnode
const { type, shapeFlag, children, dirs, props } = vnode
if (dirs) {
vnode.props = applySSRDirectives(vnode, props, dirs)
}
edison1105 marked this conversation as resolved.
Show resolved Hide resolved
switch (type) {
case Text:
push(escapeHtml(children as string))
Expand Down