Skip to content

Commit

Permalink
fix(ref): preserve ref on components after removing root element (vue…
Browse files Browse the repository at this point in the history
  • Loading branch information
javoski authored and hefeng committed Jan 25, 2019
1 parent b32590e commit 8092f0f
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 2 deletions.
2 changes: 2 additions & 0 deletions src/core/vdom/patch.js
Expand Up @@ -697,6 +697,8 @@ export function createPatchFunction (backend) {
insert.fns[i]()
}
}
} else {
registerRef(ancestor)
}
ancestor = ancestor.parent
}
Expand Down
14 changes: 12 additions & 2 deletions test/unit/features/ref.spec.js
Expand Up @@ -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: '<child ref="test"></child>',
components: {
child: {
template: '<div v-if="false"></div>'
template: '<div v-if="show"></div>',
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)
})
})

0 comments on commit 8092f0f

Please sign in to comment.