Skip to content

Commit 1d7c440

Browse files
committed
fix(compiler-ssr): handle ssr attr fallthrough when preserve whitespace
1 parent 664d2e5 commit 1d7c440

File tree

2 files changed

+28
-1
lines changed

2 files changed

+28
-1
lines changed

packages/compiler-ssr/__tests__/ssrFallthroughAttrs.spec.ts

Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -48,6 +48,31 @@ describe('ssr: attrs fallthrough', () => {
4848
`)
4949
})
5050

51+
//#8072
52+
test(`fallthrough component content (with whitespace: 'preserve')`, () => {
53+
expect(
54+
compile(
55+
`
56+
<a v-if="to">Foo</a>
57+
<a v-else>Bar</a>
58+
`,
59+
{
60+
whitespace: 'preserve',
61+
},
62+
).code,
63+
).toMatchInlineSnapshot(`
64+
"const { ssrRenderAttrs: _ssrRenderAttrs } = require("vue/server-renderer")
65+
66+
return function ssrRender(_ctx, _push, _parent, _attrs) {
67+
if (_ctx.to) {
68+
_push(\`<a\${_ssrRenderAttrs(_attrs)}>Foo</a>\`)
69+
} else {
70+
_push(\`<a\${_ssrRenderAttrs(_attrs)}>Bar</a>\`)
71+
}
72+
}"
73+
`)
74+
})
75+
5176
test('should not inject to fallthrough component content if not root', () => {
5277
expect(compile(`<div/><transition><div/></transition>`).code)
5378
.toMatchInlineSnapshot(`

packages/compiler-ssr/src/transforms/ssrInjectFallthroughAttrs.ts

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,9 @@ import {
1111
} from '@vue/compiler-dom'
1212

1313
const filterChild = (node: ParentNode) =>
14-
node.children.filter(n => n.type !== NodeTypes.COMMENT)
14+
node.children.filter(
15+
n => n.type !== NodeTypes.COMMENT && n.type !== NodeTypes.TEXT,
16+
)
1517

1618
const hasSingleChild = (node: ParentNode): boolean =>
1719
filterChild(node).length === 1

0 commit comments

Comments
 (0)