Skip to content

Commit 303824e

Browse files
committed
default slot should use fallback content when it contains all whitespace nodes (fix vuejs#5097)
1 parent 41ef650 commit 303824e

File tree

2 files changed

+8
-7
lines changed

2 files changed

+8
-7
lines changed

src/core/instance/render-helpers/resolve-slots.js

Lines changed: 6 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -29,16 +29,17 @@ export function resolveSlots (
2929
defaultSlot.push(child)
3030
}
3131
}
32-
// ignore single whitespace
33-
if (defaultSlot.length && !(
34-
defaultSlot.length === 1 &&
35-
(defaultSlot[0].text === ' ' || defaultSlot[0].isComment)
36-
)) {
32+
// ignore whitespace
33+
if (!defaultSlot.every(isWhitespace)) {
3734
slots.default = defaultSlot
3835
}
3936
return slots
4037
}
4138

39+
function isWhitespace (node: VNode): boolean {
40+
return node.isComment || node.text === ' '
41+
}
42+
4243
export function resolveScopedSlots (
4344
fns: Array<[string, Function]>
4445
): { [key: string]: Function } {

test/unit/features/component/component-slot.spec.js

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -274,10 +274,10 @@ describe('Component slot', () => {
274274
<slot name="second"><p>second named slot</p></slot>
275275
</div>
276276
`,
277-
parentContent: `<div slot="first">1</div> <div slot="second">2</div>`
277+
parentContent: `<div slot="first">1</div> <div slot="second">2</div> <div slot="second">2+</div>`
278278
})
279279
expect(child.$el.innerHTML).toBe(
280-
'<div>1</div> <p>this is the default slot</p> <div>2</div>'
280+
'<div>1</div> <p>this is the default slot</p> <div>2</div><div>2+</div>'
281281
)
282282
})
283283

0 commit comments

Comments
 (0)