diff --git a/packages/server-renderer/__tests__/renderToString.spec.ts b/packages/server-renderer/__tests__/renderToString.spec.ts
index f0ee6961..ed58e2a3 100644
--- a/packages/server-renderer/__tests__/renderToString.spec.ts
+++ b/packages/server-renderer/__tests__/renderToString.spec.ts
@@ -6,7 +6,9 @@ import {
resolveComponent,
ComponentOptions,
ref,
- defineComponent
+ defineComponent,
+ createTextVNode,
+ createStaticVNode
} from 'vue'
import { escapeHtml, mockWarn } from '@vue/shared'
import { renderToString, renderComponent } from '../src/renderToString'
@@ -511,6 +513,33 @@ describe('ssr: renderToString', () => {
})
})
+ describe('raw vnode types', () => {
+ test('Text', async () => {
+ expect(await renderToString(createTextVNode('hello
'))).toBe(
+ `hello <div>`
+ )
+ })
+
+ test('Comment', async () => {
+ // https://www.w3.org/TR/html52/syntax.html#comments
+ expect(
+ await renderToString(
+ h('div', [
+ createCommentVNode('>foo'),
+ createCommentVNode('->foo'),
+ createCommentVNode(''),
+ createCommentVNode('--!>foo
`)
+ })
+
+ test('Static', async () => {
+ const content = `helloworld
`
+ expect(await renderToString(createStaticVNode(content))).toBe(content)
+ })
+ })
+
describe('scopeId', () => {
// note: here we are only testing scopeId handling for vdom serialization.
// compiled srr render functions will include scopeId directly in strings.
diff --git a/packages/server-renderer/src/renderToString.ts b/packages/server-renderer/src/renderToString.ts
index 26a5e706..57f4ab1d 100644
--- a/packages/server-renderer/src/renderToString.ts
+++ b/packages/server-renderer/src/renderToString.ts
@@ -7,6 +7,7 @@ import {
createVNode,
Text,
Comment,
+ Static,
Fragment,
ssrUtils,
Slots,
@@ -229,6 +230,9 @@ function ssrCompile(
return (compileCache[template] = Function('require', code)(require))
}
+// https://www.w3.org/TR/html52/syntax.html#comments
+const commentStripRE = /^-?>||--!>|` : ``)
+ push(
+ children
+ ? ``
+ : ``
+ )
+ break
+ case Static:
+ push(children as string)
break
case Fragment:
push(``) // open