diff --git a/packages/server-renderer/__tests__/ssrSlot.spec.ts b/packages/server-renderer/__tests__/ssrSlot.spec.ts
new file mode 100644
index 00000000..a68569ca
--- /dev/null
+++ b/packages/server-renderer/__tests__/ssrSlot.spec.ts
@@ -0,0 +1,86 @@
+/**
+ * @jest-environment node
+ */
+
+import { createApp } from 'vue'
+import { renderToString } from '../src/renderToString'
+
+const components = {
+ one: {
+ template: `
`
+ }
+}
+
+describe('ssr: slot', () => {
+ test('text slot', async () => {
+ expect(
+ await renderToString(
+ createApp({
+ components,
+ template: `hello`
+ })
+ )
+ ).toBe(`hello
`)
+ })
+
+ test('element slot', async () => {
+ expect(
+ await renderToString(
+ createApp({
+ components,
+ template: `hi
`
+ })
+ )
+ ).toBe(``)
+ })
+
+ test('empty slot', async () => {
+ expect(
+ await renderToString(
+ createApp({
+ components: {
+ one: {
+ template: `
`
+ }
+ },
+ template: ``
+ })
+ )
+ ).toBe(``)
+ })
+
+ test('multiple elements', async () => {
+ expect(
+ await renderToString(
+ createApp({
+ components,
+ template: `one
two
`
+ })
+ )
+ ).toBe(``)
+ })
+
+ test('fragment slot (template v-if)', async () => {
+ expect(
+ await renderToString(
+ createApp({
+ components,
+ template: `hello`
+ })
+ )
+ ).toBe(`hello
`)
+ })
+
+ test('fragment slot (template v-if + multiple elements)', async () => {
+ expect(
+ await renderToString(
+ createApp({
+ components,
+ template: `one
two
`
+ })
+ )
+ ).toBe(
+ ``
+ )
+ })
+})
diff --git a/packages/server-renderer/src/helpers/ssrRenderSlot.ts b/packages/server-renderer/src/helpers/ssrRenderSlot.ts
index 967b2031..e421578d 100644
--- a/packages/server-renderer/src/helpers/ssrRenderSlot.ts
+++ b/packages/server-renderer/src/helpers/ssrRenderSlot.ts
@@ -82,7 +82,7 @@ export function ssrRenderSlotInner(
}
}
-const commentRE = /^$/
+const commentRE = //g
function isComment(item: SSRBufferItem) {
- return typeof item === 'string' && commentRE.test(item)
+ return typeof item === 'string' && !item.replace(commentRE, '').trim()
}