fix(runtime-core/template-ref): template ref used in the same template should trigger update

fix #1505
This commit is contained in:
Evan You
2020-07-06 16:40:00 -04:00
parent 64e2f46436
commit 36b6b4f022
3 changed files with 38 additions and 8 deletions

View File

@@ -5,7 +5,8 @@ import {
render,
nextTick,
defineComponent,
reactive
reactive,
serializeInner
} from '@vue/runtime-test'
// reference: https://vue-composition-api-rfc.netlify.com/api.html#template-refs
@@ -246,4 +247,25 @@ describe('api: template refs', () => {
expect(refKey2.value).toBe(root.children[2])
expect(refKey3.value).toBe(root.children[3])
})
// #1505
test('reactive template ref in the same template', async () => {
const Comp = {
setup() {
const el = ref()
return { el }
},
render(this: any) {
return h('div', { id: 'foo', ref: 'el' }, this.el && this.el.props.id)
}
}
const root = nodeOps.createElement('div')
render(h(Comp), root)
// ref not ready on first render, but should queue an update immediately
expect(serializeInner(root)).toBe(`<div id="foo"></div>`)
await nextTick()
// ref should be updated
expect(serializeInner(root)).toBe(`<div id="foo">foo</div>`)
})
})