Skip to content

Commit 55a56a6

Browse files
committed
cancel acitvate hook callback if component switches before activation (fix #1994)
1 parent 9edb358 commit 55a56a6

File tree

2 files changed

+8
-0
lines changed

2 files changed

+8
-0
lines changed

src/directives/internal/component.js

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -144,6 +144,9 @@ export default {
144144
if (activateHook && !cached) {
145145
this.waitingFor = newComponent
146146
activateHook.call(newComponent, function () {
147+
if (self.waitingFor !== newComponent) {
148+
return
149+
}
147150
self.waitingFor = null
148151
self.transition(newComponent, cb)
149152
})

test/unit/specs/directives/internal/component_spec.js

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -320,11 +320,16 @@ describe('Component', function () {
320320
// cleans up the component being waited on.
321321
// see #1152
322322
vm.view = 'view-a'
323+
// store the ready callback for view-a
324+
var callback = next
323325
_.nextTick(function () {
324326
vm.view = 'view-b'
325327
_.nextTick(function () {
326328
expect(vm.$children.length).toBe(1)
327329
expect(vm.$children[0].$el.textContent).toBe('BBB')
330+
// calling view-a's ready callback here should not throw
331+
// because it should've been cancelled (#1994)
332+
expect(callback).not.toThrow()
328333
done()
329334
})
330335
})

0 commit comments

Comments
 (0)