Skip to content

Commit

Permalink
fix(ssr): render components returning render function from setup (#720)
Browse files Browse the repository at this point in the history
  • Loading branch information
dsseng committed Feb 15, 2020
1 parent a0163f1 commit 4669215
Show file tree
Hide file tree
Showing 2 changed files with 31 additions and 3 deletions.
30 changes: 29 additions & 1 deletion packages/server-renderer/__tests__/renderToString.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,9 @@ import {
createCommentVNode,
withScopeId,
resolveComponent,
ComponentOptions
ComponentOptions,
ref,
defineComponent
} from 'vue'
import { escapeHtml, mockWarn } from '@vue/shared'
import { renderToString, renderComponent } from '../src/renderToString'
Expand Down Expand Up @@ -43,6 +45,32 @@ describe('ssr: renderToString', () => {
).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 () => {
expect(
await renderToString(
Expand Down
4 changes: 2 additions & 2 deletions packages/server-renderer/src/renderToString.ts
Original file line number Diff line number Diff line change
Expand Up @@ -177,7 +177,7 @@ function renderComponentSubTree(
if (isFunction(comp)) {
renderVNode(push, renderComponentRoot(instance), instance)
} else {
if (!comp.ssrRender && !comp.render && isString(comp.template)) {
if (!instance.render && !comp.ssrRender && isString(comp.template)) {
comp.ssrRender = ssrCompile(comp.template, instance)
}

Expand All @@ -187,7 +187,7 @@ function renderComponentSubTree(
setCurrentRenderingInstance(instance)
comp.ssrRender(instance.proxy, push, instance)
setCurrentRenderingInstance(null)
} else if (comp.render) {
} else if (instance.render) {
renderVNode(push, renderComponentRoot(instance), instance)
} else {
throw new Error(
Expand Down

0 comments on commit 4669215

Please sign in to comment.