diff --git a/packages/compiler-ssr/__tests__/ssrFallthroughAttrs.spec.ts b/packages/compiler-ssr/__tests__/ssrFallthroughAttrs.spec.ts index 7b3d1962c3e..3adfe6480d6 100644 --- a/packages/compiler-ssr/__tests__/ssrFallthroughAttrs.spec.ts +++ b/packages/compiler-ssr/__tests__/ssrFallthroughAttrs.spec.ts @@ -48,6 +48,31 @@ describe('ssr: attrs fallthrough', () => { `) }) + //#8072 + test(`fallthrough component content (with whitespace: 'preserve')`, () => { + expect( + compile( + ` + Foo + Bar + `, + { + whitespace: 'preserve', + }, + ).code, + ).toMatchInlineSnapshot(` + "const { ssrRenderAttrs: _ssrRenderAttrs } = require("vue/server-renderer") + + return function ssrRender(_ctx, _push, _parent, _attrs) { + if (_ctx.to) { + _push(\`Foo\`) + } else { + _push(\`Bar\`) + } + }" + `) + }) + test('should not inject to fallthrough component content if not root', () => { expect(compile(`
`).code) .toMatchInlineSnapshot(` diff --git a/packages/compiler-ssr/src/transforms/ssrInjectFallthroughAttrs.ts b/packages/compiler-ssr/src/transforms/ssrInjectFallthroughAttrs.ts index b1aac0d74c2..580e79ce459 100644 --- a/packages/compiler-ssr/src/transforms/ssrInjectFallthroughAttrs.ts +++ b/packages/compiler-ssr/src/transforms/ssrInjectFallthroughAttrs.ts @@ -7,11 +7,12 @@ import { type TemplateChildNode, createSimpleExpression, findDir, + isCommentOrWhitespace, locStub, } from '@vue/compiler-dom' const filterChild = (node: ParentNode) => - node.children.filter(n => n.type !== NodeTypes.COMMENT) + node.children.filter(n => !isCommentOrWhitespace(n)) const hasSingleChild = (node: ParentNode): boolean => filterChild(node).length === 1