fix(ssr): render components returning render function from setup (#720)

This commit is contained in:
Dmitry Sharshakov 2020-02-15 19:11:55 +03:00 committed by GitHub
parent a0163f1aa8
commit 4669215ca2
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 31 additions and 3 deletions

View File

@ -4,7 +4,9 @@ import {
createCommentVNode, createCommentVNode,
withScopeId, withScopeId,
resolveComponent, resolveComponent,
ComponentOptions ComponentOptions,
ref,
defineComponent
} from 'vue' } from 'vue'
import { escapeHtml, mockWarn } from '@vue/shared' import { escapeHtml, mockWarn } from '@vue/shared'
import { renderToString, renderComponent } from '../src/renderToString' import { renderToString, renderComponent } from '../src/renderToString'
@ -43,6 +45,32 @@ describe('ssr: renderToString', () => {
).toBe(`<div>hello</div>`) ).toBe(`<div>hello</div>`)
}) })
test('option components returning render from setup', async () => {
expect(
await renderToString(
createApp({
setup() {
const msg = ref('hello')
return () => h('div', msg.value)
}
})
)
).toBe(`<div>hello</div>`)
})
test('setup components returning render from setup', async () => {
expect(
await renderToString(
createApp(
defineComponent((props: {}) => {
const msg = ref('hello')
return () => h('div', msg.value)
})
)
)
).toBe(`<div>hello</div>`)
})
test('optimized components', async () => { test('optimized components', async () => {
expect( expect(
await renderToString( await renderToString(

View File

@ -177,7 +177,7 @@ function renderComponentSubTree(
if (isFunction(comp)) { if (isFunction(comp)) {
renderVNode(push, renderComponentRoot(instance), instance) renderVNode(push, renderComponentRoot(instance), instance)
} else { } else {
if (!comp.ssrRender && !comp.render && isString(comp.template)) { if (!instance.render && !comp.ssrRender && isString(comp.template)) {
comp.ssrRender = ssrCompile(comp.template, instance) comp.ssrRender = ssrCompile(comp.template, instance)
} }
@ -187,7 +187,7 @@ function renderComponentSubTree(
setCurrentRenderingInstance(instance) setCurrentRenderingInstance(instance)
comp.ssrRender(instance.proxy, push, instance) comp.ssrRender(instance.proxy, push, instance)
setCurrentRenderingInstance(null) setCurrentRenderingInstance(null)
} else if (comp.render) { } else if (instance.render) {
renderVNode(push, renderComponentRoot(instance), instance) renderVNode(push, renderComponentRoot(instance), instance)
} else { } else {
throw new Error( throw new Error(