Skip to content

Commit

Permalink
fix: fix async component resolving in sibling mounted hook
Browse files Browse the repository at this point in the history
fix #7107
  • Loading branch information
yyx990803 committed Nov 22, 2017
1 parent 604e081 commit dd21eac
Show file tree
Hide file tree
Showing 3 changed files with 38 additions and 2 deletions.
5 changes: 4 additions & 1 deletion src/core/instance/lifecycle.js
Original file line number Diff line number Diff line change
Expand Up @@ -193,7 +193,10 @@ export function mountComponent (
}
}

vm._watcher = new Watcher(vm, updateComponent, noop)
// we set this to vm._watcher inside the wathcer's constructor
// since the watcher's initial patch may call $forceUpdate (e.g. inside child
// component's mounted hook), which relies on vm._watcher being already defined
new Watcher(vm, updateComponent, noop, null, true /* isRenderWatcher */)
hydrating = false

// manually mounted instance, call mounted on self
Expand Down
6 changes: 5 additions & 1 deletion src/core/observer/watcher.js
Original file line number Diff line number Diff line change
Expand Up @@ -44,9 +44,13 @@ export default class Watcher {
vm: Component,
expOrFn: string | Function,
cb: Function,
options?: Object
options?: ?Object,
isRenderWatcher?: boolean
) {
this.vm = vm
if (isRenderWatcher) {
vm._watcher = this
}
vm._watchers.push(this)
// options
if (options) {
Expand Down
29 changes: 29 additions & 0 deletions test/unit/features/component/component-async.spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -342,5 +342,34 @@ describe('Component async', () => {
done()
}, 50)
})

// #7107
it(`should work when resolving sync in sibling component's mounted hook`, done => {
let resolveTwo

const vm = new Vue({
template: `<div><one/> <two/></div>`,
components: {
one: {
template: `<div>one</div>`,
mounted () {
resolveTwo()
}
},
two: resolve => {
resolveTwo = () => {
resolve({
template: `<div>two</div>`
})
}
}
}
}).$mount()

expect(vm.$el.textContent).toBe('one ')
waitForUpdate(() => {
expect(vm.$el.textContent).toBe('one two')
}).then(done)
})
})
})

0 comments on commit dd21eac

Please sign in to comment.