Skip to content

Commit a1b9da8

Browse files
committed
preserve reference to _data in destroyed instance so that proxy accessors still work (close vuejs#1017)
1 parent 9259325 commit a1b9da8

File tree

2 files changed

+12
-3
lines changed

2 files changed

+12
-3
lines changed

src/instance/compile.js

Lines changed: 12 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -170,8 +170,18 @@ exports._destroy = function (remove, deferCleanup) {
170170

171171
exports._cleanup = function () {
172172
// remove reference from data ob
173-
this._data.__ob__.removeVm(this)
174-
this._data =
173+
// frozen object may not have observer.
174+
if (this._data.__ob__) {
175+
this._data.__ob__.removeVm(this)
176+
}
177+
// Clean up references to private properties and other
178+
// instances. preserve reference to _data so that proxy
179+
// accessors still work. The only potential side effect
180+
// here is that mutating the instance after it's destroyed
181+
// may affect the state of other components that are still
182+
// observing the same object, but that seems to be a
183+
// reasonable responsibility for the user rather than
184+
// always throwing an error on them.
175185
this._watchers =
176186
this.$el =
177187
this.$parent =

test/unit/specs/instance/events_spec.js

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -152,7 +152,6 @@ describe('Instance Events', function () {
152152
destroyed: function () {
153153
expect(this).toBe(vm)
154154
expect(this._isDestroyed).toBe(true)
155-
expect(this._data).toBeNull()
156155
spy()
157156
}
158157
})

0 commit comments

Comments
 (0)