Skip to content

Commit d2db82f

Browse files
committed
avoid directive updates when component is being destroyed
1 parent 5ad147b commit d2db82f

File tree

3 files changed

+18
-1
lines changed

3 files changed

+18
-1
lines changed

src/directive.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -75,7 +75,7 @@ p._bind = function (def) {
7575
// wrapped updater for context
7676
var dir = this
7777
var update = this._update = function (val, oldVal) {
78-
if (!dir._locked) {
78+
if (!dir._locked && !dir.vm._isBeingDestroyed) {
7979
dir.update(val, oldVal)
8080
}
8181
}

src/directives/component.js

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -128,6 +128,10 @@ module.exports = {
128128
}
129129
}
130130
if (remove) {
131+
// setting the "being destroyed" flag before
132+
// removing to avoid content being changed during
133+
// transitions
134+
child._isBeingDestroyed = true
131135
child.$remove(destroy)
132136
} else {
133137
destroy()

test/unit/specs/directive_spec.js

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -177,4 +177,17 @@ describe('Directive', function () {
177177
})
178178
})
179179

180+
it('avoid update when vm is being destroyed', function (done) {
181+
var d = new Directive('test', el, vm, {
182+
expression: 'a',
183+
}, def)
184+
expect(def.update.calls.count()).toBe(1)
185+
vm._isBeingDestroyed = true
186+
vm.a = 2
187+
nextTick(function () {
188+
expect(def.update.calls.count()).toBe(1)
189+
done()
190+
})
191+
})
192+
180193
})

0 commit comments

Comments
 (0)