]> git.ipfire.org Git - thirdparty/vuejs/core.git/commitdiff
fix(compiler-ssr): handle ssr attr fallthrough when preserve whitespace edison/fix/8072 12304/head
authordaiwei <daiwei521@126.com>
Fri, 1 Nov 2024 03:09:43 +0000 (11:09 +0800)
committerdaiwei <daiwei521@126.com>
Fri, 1 Nov 2024 03:09:43 +0000 (11:09 +0800)
packages/compiler-ssr/__tests__/ssrFallthroughAttrs.spec.ts
packages/compiler-ssr/src/transforms/ssrInjectFallthroughAttrs.ts

index 7b3d1962c3e0947f30acd2d960870d69bbd4a460..3adfe6480d667e282bfecaeac24b81b51ebb85d7 100644 (file)
@@ -48,6 +48,31 @@ describe('ssr: attrs fallthrough', () => {
       `)
   })
 
+  //#8072
+  test(`fallthrough component content (with whitespace: 'preserve')`, () => {
+    expect(
+      compile(
+        `
+      <a v-if="to">Foo</a>
+      <a v-else>Bar</a>
+    `,
+        {
+          whitespace: 'preserve',
+        },
+      ).code,
+    ).toMatchInlineSnapshot(`
+        "const { ssrRenderAttrs: _ssrRenderAttrs } = require("vue/server-renderer")
+
+        return function ssrRender(_ctx, _push, _parent, _attrs) {
+          if (_ctx.to) {
+            _push(\`<a\${_ssrRenderAttrs(_attrs)}>Foo</a>\`)
+          } else {
+            _push(\`<a\${_ssrRenderAttrs(_attrs)}>Bar</a>\`)
+          }
+        }"
+      `)
+  })
+
   test('should not inject to fallthrough component content if not root', () => {
     expect(compile(`<div/><transition><div/></transition>`).code)
       .toMatchInlineSnapshot(`
index b1aac0d74c2fd8b044fc30c6f4b4694f97d61c4b..045783aa63d9792c8e2fcf9bc3d64441a70537ef 100644 (file)
@@ -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