Browse Source

fix: force update between two components with and without slot (#11795)

dev
ygj6 4 years ago
committed by GitHub
parent
commit
77b5330c54
No known key found for this signature in database GPG Key ID: 4AEE18F83AFDEB23
  1. 3
      src/core/instance/lifecycle.js
  2. 24
      test/unit/features/component/component-scoped-slot.spec.js

3
src/core/instance/lifecycle.js

@ -234,7 +234,8 @@ export function updateChildComponent (
const hasDynamicScopedSlot = !!( const hasDynamicScopedSlot = !!(
(newScopedSlots && !newScopedSlots.$stable) || (newScopedSlots && !newScopedSlots.$stable) ||
(oldScopedSlots !== emptyObject && !oldScopedSlots.$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 // Any static slot children from the parent may have changed during parent's

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

@ -1325,4 +1325,28 @@ describe('Component scoped slot', () => {
expect(vm.$el.textContent).toMatch(`1`) expect(vm.$el.textContent).toMatch(`1`)
}).then(done) }).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)
})
}) })

Loading…
Cancel
Save