Skip to content

Commit 77b5330

Browse files
authoredApr 16, 2021
fix: force update between two components with and without slot (#11795)
1 parent af54514 commit 77b5330

File tree

2 files changed

+26
-1
lines changed

2 files changed

+26
-1
lines changed
 

‎src/core/instance/lifecycle.js

+2-1
Original file line numberDiff line numberDiff line change
@@ -234,7 +234,8 @@ export function updateChildComponent (
234234
const hasDynamicScopedSlot = !!(
235235
(newScopedSlots && !newScopedSlots.$stable) ||
236236
(oldScopedSlots !== emptyObject && !oldScopedSlots.$stable) ||
237-
(newScopedSlots && vm.$scopedSlots.$key !== newScopedSlots.$key)
237+
(newScopedSlots && vm.$scopedSlots.$key !== newScopedSlots.$key) ||
238+
(!newScopedSlots && vm.$scopedSlots.$key)
238239
)
239240

240241
// Any static slot children from the parent may have changed during parent's

‎test/unit/features/component/component-scoped-slot.spec.js

+24
Original file line numberDiff line numberDiff line change
@@ -1325,4 +1325,28 @@ describe('Component scoped slot', () => {
13251325
expect(vm.$el.textContent).toMatch(`1`)
13261326
}).then(done)
13271327
})
1328+
1329+
// #11652
1330+
it('should update when swtching between two components with slot and without slot', done => {
1331+
const Child = {
1332+
template: `<div><slot/></div>`
1333+
}
1334+
1335+
const parent = new Vue({
1336+
template: `<div>
1337+
<child v-if="flag"><template #default>foo</template></child>
1338+
<child v-else></child>
1339+
</div>`,
1340+
data: {
1341+
flag: true
1342+
},
1343+
components: { Child }
1344+
}).$mount()
1345+
1346+
expect(parent.$el.textContent).toMatch(`foo`)
1347+
parent.flag=false
1348+
waitForUpdate(()=>{
1349+
expect(parent.$el.textContent).toMatch(``)
1350+
}).then(done)
1351+
})
13281352
})

0 commit comments

Comments
 (0)
Please sign in to comment.