diff --git a/src/core/vdom/patch.js b/src/core/vdom/patch.js index 40a4a0ccb45..2918e621b0d 100644 --- a/src/core/vdom/patch.js +++ b/src/core/vdom/patch.js @@ -697,6 +697,8 @@ export function createPatchFunction (backend) { insert.fns[i]() } } + } else { + registerRef(ancestor) } ancestor = ancestor.parent } diff --git a/test/unit/features/ref.spec.js b/test/unit/features/ref.spec.js index f82efe4513a..05efc4d5244 100644 --- a/test/unit/features/ref.spec.js +++ b/test/unit/features/ref.spec.js @@ -196,15 +196,25 @@ describe('ref', () => { } }) - it('should register on component with empty roots', () => { + it('should register on component with empty roots', done => { const vm = new Vue({ template: '', components: { child: { - template: '
' + template: '
', + data () { + return { show: false } + } } } }).$mount() expect(vm.$refs.test).toBe(vm.$children[0]) + vm.$refs.test.show = true + waitForUpdate(() => { + expect(vm.$refs.test).toBe(vm.$children[0]) + vm.$refs.test.show = false + }).then(() => { + expect(vm.$refs.test).toBe(vm.$children[0]) + }).then(done) }) })