Skip to content

Commit e2ef3e8

Browse files
committed
default slot should use fallback content if it has only whitespace (fix #2723)
1 parent f536ebe commit e2ef3e8

File tree

2 files changed

+27
-0
lines changed

2 files changed

+27
-0
lines changed

src/compiler/resolve-slots.js

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -38,6 +38,14 @@ export function resolveSlots (vm, content) {
3838
contents[name] = extractFragment(contents[name], content)
3939
}
4040
if (content.hasChildNodes()) {
41+
const nodes = content.childNodes
42+
if (
43+
nodes.length === 1 &&
44+
nodes[0].nodeType === 3 &&
45+
!nodes[0].data.trim()
46+
) {
47+
return
48+
}
4149
contents['default'] = extractFragment(content.childNodes, content)
4250
}
4351
}

test/unit/specs/directives/element/slot_spec.js

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -457,4 +457,23 @@ describe('Slot Distribution', function () {
457457
})
458458
expect('"slot" attribute must be static').toHaveBeenWarned()
459459
})
460+
461+
it('default slot should use fallback content if has only whitespace', () => {
462+
new Vue({
463+
el: el,
464+
template: '<test><div slot="first">1</div> <div slot="second">2</div></test>',
465+
components: {
466+
test: {
467+
replace: true,
468+
template:
469+
'<div class="wrapper">' +
470+
'<slot name="first"><p>first slot</p></slot>' +
471+
'<slot><p>this is the default slot</p></slot>' +
472+
'<slot name="second"><p>second named slot</p></slot>' +
473+
'</div>'
474+
}
475+
}
476+
})
477+
expect(el.children[0].innerHTML).toBe('<div slot="first">1</div><p>this is the default slot</p><div slot="second">2</div>')
478+
})
460479
})

0 commit comments

Comments
 (0)