Skip to content

Commit

Permalink
fix: avoid exposing internal flags on $scopedSlots
Browse files Browse the repository at this point in the history
ref #9443
  • Loading branch information
yyx990803 committed Feb 6, 2019
1 parent 54e6a12 commit 24b4640
Show file tree
Hide file tree
Showing 4 changed files with 27 additions and 25 deletions.
1 change: 1 addition & 0 deletions src/core/instance/lifecycle.js
Original file line number Diff line number Diff line change
Expand Up @@ -233,6 +233,7 @@ export function updateChildComponent (
(parentVnode.data.scopedSlots && !parentVnode.data.scopedSlots.$stable) ||
(vm.$scopedSlots !== emptyObject && !vm.$scopedSlots.$stable)
)

// Any static slot children from the parent may have changed during parent's
// update. Dynamic scoped slots may also have changed. In such cases, a forced
// update is necessary to ensure correctness.
Expand Down
5 changes: 3 additions & 2 deletions src/core/vdom/helpers/normalize-scoped-slots.js
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
/* @flow */

import { hasOwn } from 'shared/util'
import { def } from 'core/util/lang'
import { normalizeChildren } from 'core/vdom/helpers/normalize-children'

export function normalizeScopedSlots (
Expand All @@ -26,8 +27,8 @@ export function normalizeScopedSlots (
res[key] = proxyNormalSlot(normalSlots, key)
}
}
res._normalized = true
res.$stable = slots ? slots.$stable : true
def(res, '_normalized', true)
def(res, '$stable', slots ? !!slots.$stable : true)
return res
}

Expand Down
23 changes: 23 additions & 0 deletions test/unit/features/component/component-scoped-slot.spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -969,4 +969,27 @@ describe('Component scoped slot', () => {
}).then(done)
}
})

// regression #9396
it('should not force update child with no slot content', done => {
const Child = {
updated: jasmine.createSpy(),
template: `<div></div>`
}

const parent = new Vue({
template: `<div>{{ count }}<child/></div>`,
data: {
count: 0
},
components: { Child }
}).$mount()

expect(parent.$el.textContent).toBe(`0`)
parent.count++
waitForUpdate(() => {
expect(parent.$el.textContent).toBe(`1`)
expect(Child.updated).not.toHaveBeenCalled()
}).then(done)
})
})
23 changes: 0 additions & 23 deletions test/unit/modules/vdom/patch/edge-cases.spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -410,27 +410,4 @@ describe('vdom patch: edge cases', () => {
expect(vm.$el.textContent).toBe('FooBar')
expect(inlineHookSpy.calls.count()).toBe(2)
})

// regression #9396
it('should not force update child with no slot content', done => {
const Child = {
updated: jasmine.createSpy(),
template: `<div></div>`
}

const parent = new Vue({
template: `<div>{{ count }}<child/></div>`,
data: {
count: 0
},
components: { Child }
}).$mount()

expect(parent.$el.textContent).toBe(`0`)
parent.count++
waitForUpdate(() => {
expect(parent.$el.textContent).toBe(`1`)
expect(Child.updated).not.toHaveBeenCalled()
}).then(done)
})
})

0 comments on commit 24b4640

Please sign in to comment.