Skip to content

fix(compiler): fix nested v-slot not updating when used with v-if/v-else #10377

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 1 commit into
base: dev
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 7 additions & 0 deletions src/compiler/parser/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -698,6 +698,13 @@ function processSlotContent (el) {
slotContainer.children = el.children.filter((c: any) => {
if (!c.slotScope) {
c.parent = slotContainer
if (c.ifConditions) {
// #10330
// update every element's parent when it is in the other condition branch
// so we can find correctly whether the element is inside another scoped slot when
// generating scoped slot's rendering code, and this will trigger force updating
c.ifConditions.forEach(({block}) => block.parent = slotContainer)
}
return true
}
})
Expand Down
35 changes: 35 additions & 0 deletions test/unit/features/component/component-scoped-slot.spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -1325,4 +1325,39 @@ describe('Component scoped slot', () => {
expect(vm.$el.textContent).toMatch(`1`)
}).then(done)
})

// #10330
it('nested v-slot should be reactive when v-slot on component itself combined with v-if/v-else', done => {
const Container = {
template: `<div><slot v-bind="n" /></div>`,
props: ['n']
}

const Nested = {
template: `<div><slot v-bind="m" /></div>`,
props: ['m']
}

const vm = new Vue({
data: {
n: { value: 0 },
disabled: false
},
components: { Container, Nested },
template: `
<container v-slot="n" :n="n">
<div v-if="disabled">Disabled</div>
<nested v-else v-slot="m" :m="n">
{{n.value}} {{m.value}}
</nested>
</container>
`
}).$mount()

expect(vm.$el.textContent).toMatch(`0 0`)
vm.n.value++
waitForUpdate(() => {
expect(vm.$el.textContent).toMatch(`1 1`)
}).then(done)
})
})