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: should dynamically update refs in context #764

Merged
merged 1 commit into from Jul 16, 2021
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
3 changes: 3 additions & 0 deletions src/mixin.ts
Expand Up @@ -35,6 +35,9 @@ export function mixin(Vue: VueConstructor) {
},
updated(this: ComponentInstance) {
updateTemplateRef(this)
if (this.$vnode?.context) {
updateTemplateRef(this.$vnode.context)
}
},
})

Expand Down
46 changes: 45 additions & 1 deletion test/templateRefs.spec.js
@@ -1,5 +1,5 @@
const Vue = require('vue/dist/vue.common.js')
const { ref, watchEffect } = require('../src')
const { ref, watchEffect, nextTick } = require('../src')

describe('ref', () => {
it('should work', (done) => {
Expand Down Expand Up @@ -69,6 +69,50 @@ describe('ref', () => {
.then(done)
})

// #296
it('should dynamically update refs in context', async () => {
const vm = new Vue({
setup() {
const barRef = ref(null)
return {
barRef,
}
},
template: `<div>
<foo><bar ref="barRef"/></foo>
</div>`,
components: {
bar: {
setup() {
const name = ref('bar')
return {
name,
}
},
template: '<div> {{name}} </div>',
},
foo: {
setup() {
const showSlot = ref(false)
const setShow = () => {
showSlot.value = true
}
return {
setShow,
showSlot,
}
},
template: `<div> <slot v-if="showSlot"></slot> </div>`,
},
},
}).$mount()
await nextTick()
//@ts-ignore
vm.$children[0].setShow()
await nextTick()
//@ts-ignore
expect(vm.$refs.barRef).toBe(vm.barRef)
})
// TODO: how ?
// it('work with createElement', () => {
// let root;
Expand Down