Skip to content

Commit

Permalink
fix(ref): preserve ref on components after removing root element (#6718)
Browse files Browse the repository at this point in the history
  • Loading branch information
javoski authored and yyx990803 committed Oct 3, 2017
1 parent baabd6d commit 6ad44e1
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
Original file line number Diff line number Diff line change
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
Original file line number Diff line number Diff line change
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 6ad44e1

Please sign in to comment.