From 060686d6ea4d013129b4d2e93d7d2e5c93e09686 Mon Sep 17 00:00:00 2001 From: Evan You Date: Sun, 10 Feb 2019 22:23:22 -0500 Subject: [PATCH] fix: do not cache scoped slots when mixed with normal slots --- .../vdom/helpers/normalize-scoped-slots.js | 10 ++++++-- .../component/component-scoped-slot.spec.js | 25 +++++++++++++++++++ 2 files changed, 33 insertions(+), 2 deletions(-) diff --git a/src/core/vdom/helpers/normalize-scoped-slots.js b/src/core/vdom/helpers/normalize-scoped-slots.js index e4a54f1fbff..813f570589d 100644 --- a/src/core/vdom/helpers/normalize-scoped-slots.js +++ b/src/core/vdom/helpers/normalize-scoped-slots.js @@ -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 = {} diff --git a/test/unit/features/component/component-scoped-slot.spec.js b/test/unit/features/component/component-scoped-slot.spec.js index 3bf91c087c9..b87b3600099 100644 --- a/test/unit/features/component/component-scoped-slot.spec.js +++ b/test/unit/features/component/component-scoped-slot.spec.js @@ -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 => { + const foo = { + template: `
` + } + + const vm = new Vue({ + data: { + msg: 'foo' + }, + template: ` + +
{{ msg }}
+ +
+ `, + components: { foo } + }).$mount() + + expect(vm.$el.textContent).toBe(`foo bar`) + vm.msg = 'baz' + waitForUpdate(() => { + expect(vm.$el.textContent).toBe(`baz bar`) + }).then(done) + }) })