Skip to content

Commit

Permalink
fix: empty scoped slot should return undefined
Browse files Browse the repository at this point in the history
fix #9452
  • Loading branch information
yyx990803 committed Feb 7, 2019
1 parent 4015deb commit 57bc80a
Show file tree
Hide file tree
Showing 2 changed files with 30 additions and 2 deletions.
7 changes: 5 additions & 2 deletions src/core/vdom/helpers/normalize-scoped-slots.js
Expand Up @@ -33,10 +33,13 @@ export function normalizeScopedSlots (

function normalizeScopedSlot(fn: Function): Function {
return scope => {
const res = fn(scope)
return res && typeof res === 'object' && !Array.isArray(res)
let res = fn(scope)
res = res && typeof res === 'object' && !Array.isArray(res)
? [res] // single vnode
: normalizeChildren(res)
return res && res.length === 0
? undefined
: res
}
}

Expand Down
25 changes: 25 additions & 0 deletions test/unit/features/component/component-scoped-slot.spec.js
Expand Up @@ -1034,4 +1034,29 @@ describe('Component scoped slot', () => {
expect(vm.$el.textContent).toBe(JSON.stringify({ changed: 'hello' }, null, 2))
}).then(done)
})

// #9452
it('fallback for scoped slots passed multiple levels down', () => {
const inner = {
template: `<div><slot>fallback</slot></div>`
}

const wrapper = {
template: `
<inner>
<template #default>
<slot/>
</template>
</inner>
`,
components: { inner }
}

const vm = new Vue({
components: { wrapper, inner },
template: `<wrapper/>`
}).$mount()

expect(vm.$el.textContent).toBe(`fallback`)
})
})

0 comments on commit 57bc80a

Please sign in to comment.