From: Evan You Date: Thu, 30 Jan 2020 02:13:34 +0000 (-0500) Subject: test(ssr): test scopeId handling in vdom serialization X-Git-Tag: v3.0.0-alpha.5~152 X-Git-Url: http://git.ipfire.org/gitweb.cgi?a=commitdiff_plain;h=94e80cf6d1428c1c42d4a37b8ac6170fa207d627;p=thirdparty%2Fvuejs%2Fcore.git test(ssr): test scopeId handling in vdom serialization --- diff --git a/packages/server-renderer/__tests__/renderToString.spec.ts b/packages/server-renderer/__tests__/renderToString.spec.ts index a41c4eedc6..1736d08f76 100644 --- a/packages/server-renderer/__tests__/renderToString.spec.ts +++ b/packages/server-renderer/__tests__/renderToString.spec.ts @@ -1,4 +1,4 @@ -import { createApp, h, createCommentVNode } from 'vue' +import { createApp, h, createCommentVNode, withScopeId } from 'vue' import { renderToString, renderComponent, renderSlot, escapeHtml } from '../src' describe('ssr: renderToString', () => { @@ -327,6 +327,41 @@ describe('ssr: renderToString', () => { }) describe('scopeId', () => { - // TODO + // note: here we are only testing scopeId handling for vdom serialization. + // compiled srr render functions will include scopeId directly in strings. + const withId = withScopeId('data-v-test') + const withChildId = withScopeId('data-v-child') + + test('basic', async () => { + expect( + await renderToString( + withId(() => { + return h('div') + })() + ) + ).toBe(`
`) + }) + + test('with slots', async () => { + const Child = { + __scopeId: 'data-v-child', + render: withChildId(function(this: any) { + return h('div', this.$slots.default()) + }) + } + + const Parent = { + __scopeId: 'data-v-test', + render: withId(() => { + return h(Child, null, { + default: withId(() => h('span', 'slot')) + }) + }) + } + + expect(await renderToString(h(Parent))).toBe( + `
slot
` + ) + }) }) }) diff --git a/packages/server-renderer/src/renderToString.ts b/packages/server-renderer/src/renderToString.ts index 7cd7c25ce7..ebf96624cf 100644 --- a/packages/server-renderer/src/renderToString.ts +++ b/packages/server-renderer/src/renderToString.ts @@ -222,7 +222,7 @@ function renderElement( // vnode's own scopeId and the current rendering component's scopeId is // different - this is a slot content node. if (treeOwnerId != null && treeOwnerId !== scopeId) { - openTag += ` ${scopeId}-s` + openTag += ` ${treeOwnerId}-s` } }