Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix(lifecycle): beforeUpdated should not be called if component is de… #9171

Merged
merged 3 commits into from Dec 11, 2018
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
2 changes: 1 addition & 1 deletion src/core/instance/lifecycle.js
Expand Up @@ -196,7 +196,7 @@ export function mountComponent (
// component's mounted hook), which relies on vm._watcher being already defined
new Watcher(vm, updateComponent, noop, {
before () {
if (vm._isMounted) {
if (vm._isMounted && !vm._isDestroyed) {
callHook(vm, 'beforeUpdate')
}
}
Expand Down
37 changes: 37 additions & 0 deletions test/unit/features/options/lifecycle.spec.js
Expand Up @@ -152,6 +152,43 @@ describe('Options lifecycle hooks', () => {
expect(vm.$el.textContent).toBe('bar!')
}).then(done)
})

// #8076
it('should not be called after destroy', done => {
const beforeUpdated = jasmine.createSpy('beforeUpdated')
Copy link
Member

@posva posva Dec 10, 2018

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think you meant beforeUpdate

Suggested change
const beforeUpdated = jasmine.createSpy('beforeUpdated')
const beforeUpdate = jasmine.createSpy('beforeUpdate')

const destroyed = jasmine.createSpy('destroyed')

Vue.component('todo', {
template: '<div>{{todo.done}}</div>',
props: ['todo'],
destroyed,
beforeUpdated
})

const vm = new Vue({
template: `
<div>
<todo v-for="t in pendingTodos" :todo="t" :key="t.id"></todo>
</div>
`,
data () {
return {
todos: [{ id: 1, done: false }]
}
},
computed: {
pendingTodos () {
return this.todos.filter(t => !t.done)
}
}
}).$mount()

vm.todos[0].done = true
waitForUpdate(() => {
expect(destroyed).toHaveBeenCalled()
expect(beforeUpdated).not.toHaveBeenCalled()
therealpecus marked this conversation as resolved.
Show resolved Hide resolved
}).then(done)
})
})

describe('updated', () => {
Expand Down