Skip to content

Commit

Permalink
fix: force update between two components with and without slot (#11795)
Browse files Browse the repository at this point in the history
  • Loading branch information
ygj6 committed Apr 16, 2021
1 parent af54514 commit 77b5330
Show file tree
Hide file tree
Showing 2 changed files with 26 additions and 1 deletion.
3 changes: 2 additions & 1 deletion src/core/instance/lifecycle.js
Expand Up @@ -234,7 +234,8 @@ export function updateChildComponent (
const hasDynamicScopedSlot = !!(
(newScopedSlots && !newScopedSlots.$stable) ||
(oldScopedSlots !== emptyObject && !oldScopedSlots.$stable) ||
(newScopedSlots && vm.$scopedSlots.$key !== newScopedSlots.$key)
(newScopedSlots && vm.$scopedSlots.$key !== newScopedSlots.$key) ||
(!newScopedSlots && vm.$scopedSlots.$key)
)

// Any static slot children from the parent may have changed during parent's
Expand Down
24 changes: 24 additions & 0 deletions test/unit/features/component/component-scoped-slot.spec.js
Expand Up @@ -1325,4 +1325,28 @@ describe('Component scoped slot', () => {
expect(vm.$el.textContent).toMatch(`1`)
}).then(done)
})

// #11652
it('should update when swtching between two components with slot and without slot', done => {
const Child = {
template: `<div><slot/></div>`
}

const parent = new Vue({
template: `<div>
<child v-if="flag"><template #default>foo</template></child>
<child v-else></child>
</div>`,
data: {
flag: true
},
components: { Child }
}).$mount()

expect(parent.$el.textContent).toMatch(`foo`)
parent.flag=false
waitForUpdate(()=>{
expect(parent.$el.textContent).toMatch(``)
}).then(done)
})
})

0 comments on commit 77b5330

Please sign in to comment.