Skip to content

Commit

Permalink
fix: do not cache scoped slots when mixed with normal slots
Browse files Browse the repository at this point in the history
  • Loading branch information
yyx990803 committed Feb 11, 2019
1 parent 0bad7e2 commit 060686d
Show file tree
Hide file tree
Showing 2 changed files with 33 additions and 2 deletions.
10 changes: 8 additions & 2 deletions src/core/vdom/helpers/normalize-scoped-slots.js
Expand Up @@ -15,8 +15,14 @@ export function normalizeScopedSlots (
} else if (slots._normalized) {
// fast path 1: child component re-render only, parent did not change
return slots._normalized
} else if (slots.$stable && prevSlots && prevSlots !== emptyObject) {
// fast path 2: stable scoped slots, only need to normalize once
} else if (
slots.$stable &&
prevSlots &&
prevSlots !== emptyObject &&
Object.keys(normalSlots).length === 0
) {
// fast path 2: stable scoped slots w/ no normal slots to proxy,
// only need to normalize once
return prevSlots
} else {
res = {}
Expand Down
25 changes: 25 additions & 0 deletions test/unit/features/component/component-scoped-slot.spec.js
Expand Up @@ -1103,4 +1103,29 @@ describe('Component scoped slot', () => {
}).$mount()
expect(vm.$el.textContent).toBe('hello')
})

it('should not cache scoped slot normalzation when there are a mix of normal and scoped slots', done => {

This comment has been minimized.

Copy link
@johnleider

johnleider Feb 11, 2019

Contributor

normalzation -> normalization

const foo = {
template: `<div><slot name="foo" /> <slot name="bar" /></div>`
}

const vm = new Vue({
data: {
msg: 'foo'
},
template: `
<foo>
<div slot="foo">{{ msg }}</div>
<template #bar><div>bar</div></template>
</foo>
`,
components: { foo }
}).$mount()

expect(vm.$el.textContent).toBe(`foo bar`)
vm.msg = 'baz'
waitForUpdate(() => {
expect(vm.$el.textContent).toBe(`baz bar`)
}).then(done)
})
})

0 comments on commit 060686d

Please sign in to comment.