Skip to content
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

fix(compiler): nested scoped slot not update (fix #12232, #12245) #12265

Open
wants to merge 1 commit into
base: dev
Choose a base branch
from
Open
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
fix(compiler): nested scoped slot not update (fix #12232, #12245)
  • Loading branch information
JuniorTour committed Jun 18, 2022
commit c2ec22ea95d2ef1b0b40a0800f61076b3ef097e8
9 changes: 8 additions & 1 deletion src/compiler/codegen/index.js
Original file line number Diff line number Diff line change
@@ -430,7 +430,14 @@ function containsSlotChild (el: ASTNode): boolean {
if (el.tag === 'slot') {
return true
}
return el.children.some(containsSlotChild)
// #12232, #12245: nested scoped slot should update
const childrenIsDynamic = el.children.some(containsSlotChild)
if (childrenIsDynamic) {
return childrenIsDynamic
} else if (el.scopedSlots) {
const scopedSlots = el.scopedSlots
return Object.keys(scopedSlots).some(key => containsSlotChild(scopedSlots[key]))
}
}
return false
}
66 changes: 66 additions & 0 deletions test/unit/features/component/component-scoped-slot.spec.js
Original file line number Diff line number Diff line change
@@ -1026,6 +1026,72 @@ describe('Component scoped slot', () => {
}).then(done)
})

// #12232, #12245
it('nested named scoped slots should update', done => {
const initialText = 'initial'
const scopedSlotContent = 'scopedSlot'

const inner = {
template: `<div><slot v-bind="{ user: '${scopedSlotContent}' }"/></div>`
}

const innerContainer = {
template: `<div><slot name="content"/></div>`
}

const wrapper = {
components: { inner, innerContainer },
name: 'wrapper',
template: `
<inner v-slot="{ user }">
<innerContainer>
<template #content>
<div>
<span>{{ user }}</span>
<slot/>
</div>
</template>
</innerContainer>
</inner>
`
}

const outer = {
components: { wrapper },
template: `
<wrapper>
<form>
<span>{{ text }}</span>
<input v-model="text" type="text"/>
</form>
</wrapper>
`,
data() {
return {
text: initialText,
}
},
}

const vm = new Vue({
components: { outer },
template: `<outer ref="outer"></outer>`
}).$mount()

expect(vm.$el.textContent).toBe(`${scopedSlotContent} ${initialText} `)

const newValue = 'newValue'
vm.$refs.outer.text = newValue
const input = vm.$el.querySelector('input')
input.value = newValue
triggerEvent(input, 'input')

waitForUpdate(() => {
expect(vm.$el.textContent).toBe(`${scopedSlotContent} ${newValue} `)
expect(input.value).toBe(newValue)
}).then(done)
})

it('dynamic v-bind arguments on <slot>', done => {
const Foo = {
data() {