From: daiwei Date: Fri, 1 Nov 2024 03:09:43 +0000 (+0800) Subject: fix(compiler-ssr): handle ssr attr fallthrough when preserve whitespace X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=refs%2Fpull%2F12304%2Fhead;p=thirdparty%2Fvuejs%2Fcore.git fix(compiler-ssr): handle ssr attr fallthrough when preserve whitespace --- diff --git a/packages/compiler-ssr/__tests__/ssrFallthroughAttrs.spec.ts b/packages/compiler-ssr/__tests__/ssrFallthroughAttrs.spec.ts index 7b3d1962c3..3adfe6480d 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 b1aac0d74c..045783aa63 100644 --- a/packages/compiler-ssr/src/transforms/ssrInjectFallthroughAttrs.ts +++ b/packages/compiler-ssr/src/transforms/ssrInjectFallthroughAttrs.ts @@ -11,7 +11,9 @@ import { } from '@vue/compiler-dom' const filterChild = (node: ParentNode) => - node.children.filter(n => n.type !== NodeTypes.COMMENT) + node.children.filter( + n => n.type !== NodeTypes.COMMENT && n.type !== NodeTypes.TEXT, + ) const hasSingleChild = (node: ParentNode): boolean => filterChild(node).length === 1