From f5958584d93665d23fa0d37b02b7bc66caf31b8f Mon Sep 17 00:00:00 2001 From: Rich Harris Date: Thu, 31 Aug 2017 13:26:12 -0400 Subject: [PATCH] dont noop set/get until after component is destroyed (fixes #788) --- src/shared/index.js | 3 ++- .../expected-bundle.js | 3 ++- .../computed-collapsed-if/expected-bundle.js | 3 ++- .../css-media-query/expected-bundle.js | 3 ++- .../expected-bundle.js | 3 ++- .../event-handlers-custom/expected-bundle.js | 3 ++- .../if-block-no-update/expected-bundle.js | 3 ++- .../if-block-simple/expected-bundle.js | 3 ++- .../legacy-input-type/expected-bundle.js | 3 ++- .../non-imported-component/expected-bundle.js | 3 ++- .../expected-bundle.js | 3 ++- .../samples/setup-method/expected-bundle.js | 3 ++- .../expected-bundle.js | 3 ++- .../_config.js | 0 .../main.html | 0 .../samples/set-in-ondestroy/_config.js | 26 +++++++++++++++++++ .../samples/set-in-ondestroy/main.html | 1 + 17 files changed, 53 insertions(+), 13 deletions(-) rename test/runtime/samples/{set-in-onrender => set-in-oncreate}/_config.js (100%) rename test/runtime/samples/{set-in-onrender => set-in-oncreate}/main.html (100%) create mode 100644 test/runtime/samples/set-in-ondestroy/_config.js create mode 100644 test/runtime/samples/set-in-ondestroy/main.html diff --git a/src/shared/index.js b/src/shared/index.js index 7813987837..fdd267d902 100644 --- a/src/shared/index.js +++ b/src/shared/index.js @@ -5,8 +5,9 @@ export * from './transitions.js'; export * from './utils.js'; export function destroy(detach) { - this.destroy = this.set = this.get = noop; + this.destroy = noop; this.fire('destroy'); + this.set = this.get = noop; if (detach !== false) this._fragment.unmount(); this._fragment.destroy(); diff --git a/test/js/samples/collapses-text-around-comments/expected-bundle.js b/test/js/samples/collapses-text-around-comments/expected-bundle.js index 9d9d6a7f3d..b485e8ae40 100644 --- a/test/js/samples/collapses-text-around-comments/expected-bundle.js +++ b/test/js/samples/collapses-text-around-comments/expected-bundle.js @@ -38,8 +38,9 @@ function setAttribute(node, attribute, value) { } function destroy(detach) { - this.destroy = this.set = this.get = noop; + this.destroy = noop; this.fire('destroy'); + this.set = this.get = noop; if (detach !== false) this._fragment.unmount(); this._fragment.destroy(); diff --git a/test/js/samples/computed-collapsed-if/expected-bundle.js b/test/js/samples/computed-collapsed-if/expected-bundle.js index 36b0c20402..8f13660642 100644 --- a/test/js/samples/computed-collapsed-if/expected-bundle.js +++ b/test/js/samples/computed-collapsed-if/expected-bundle.js @@ -14,8 +14,9 @@ function assign(target) { } function destroy(detach) { - this.destroy = this.set = this.get = noop; + this.destroy = noop; this.fire('destroy'); + this.set = this.get = noop; if (detach !== false) this._fragment.unmount(); this._fragment.destroy(); diff --git a/test/js/samples/css-media-query/expected-bundle.js b/test/js/samples/css-media-query/expected-bundle.js index a9b624b079..9b5f69f529 100644 --- a/test/js/samples/css-media-query/expected-bundle.js +++ b/test/js/samples/css-media-query/expected-bundle.js @@ -34,8 +34,9 @@ function setAttribute(node, attribute, value) { } function destroy(detach) { - this.destroy = this.set = this.get = noop; + this.destroy = noop; this.fire('destroy'); + this.set = this.get = noop; if (detach !== false) this._fragment.unmount(); this._fragment.destroy(); diff --git a/test/js/samples/each-block-changed-check/expected-bundle.js b/test/js/samples/each-block-changed-check/expected-bundle.js index 3ddd408a05..6353bf3ee1 100644 --- a/test/js/samples/each-block-changed-check/expected-bundle.js +++ b/test/js/samples/each-block-changed-check/expected-bundle.js @@ -47,8 +47,9 @@ function createText(data) { } function destroy(detach) { - this.destroy = this.set = this.get = noop; + this.destroy = noop; this.fire('destroy'); + this.set = this.get = noop; if (detach !== false) this._fragment.unmount(); this._fragment.destroy(); diff --git a/test/js/samples/event-handlers-custom/expected-bundle.js b/test/js/samples/event-handlers-custom/expected-bundle.js index ba38124b0a..159e569519 100644 --- a/test/js/samples/event-handlers-custom/expected-bundle.js +++ b/test/js/samples/event-handlers-custom/expected-bundle.js @@ -34,8 +34,9 @@ function createText(data) { } function destroy(detach) { - this.destroy = this.set = this.get = noop; + this.destroy = noop; this.fire('destroy'); + this.set = this.get = noop; if (detach !== false) this._fragment.unmount(); this._fragment.destroy(); diff --git a/test/js/samples/if-block-no-update/expected-bundle.js b/test/js/samples/if-block-no-update/expected-bundle.js index 4e9a0bcf69..3f5fd5ceab 100644 --- a/test/js/samples/if-block-no-update/expected-bundle.js +++ b/test/js/samples/if-block-no-update/expected-bundle.js @@ -38,8 +38,9 @@ function createComment() { } function destroy(detach) { - this.destroy = this.set = this.get = noop; + this.destroy = noop; this.fire('destroy'); + this.set = this.get = noop; if (detach !== false) this._fragment.unmount(); this._fragment.destroy(); diff --git a/test/js/samples/if-block-simple/expected-bundle.js b/test/js/samples/if-block-simple/expected-bundle.js index 230b781c42..5de96e35cc 100644 --- a/test/js/samples/if-block-simple/expected-bundle.js +++ b/test/js/samples/if-block-simple/expected-bundle.js @@ -38,8 +38,9 @@ function createComment() { } function destroy(detach) { - this.destroy = this.set = this.get = noop; + this.destroy = noop; this.fire('destroy'); + this.set = this.get = noop; if (detach !== false) this._fragment.unmount(); this._fragment.destroy(); diff --git a/test/js/samples/legacy-input-type/expected-bundle.js b/test/js/samples/legacy-input-type/expected-bundle.js index d636262a36..9730de31f9 100644 --- a/test/js/samples/legacy-input-type/expected-bundle.js +++ b/test/js/samples/legacy-input-type/expected-bundle.js @@ -32,8 +32,9 @@ function setInputType(input, type) { } function destroy(detach) { - this.destroy = this.set = this.get = noop; + this.destroy = noop; this.fire('destroy'); + this.set = this.get = noop; if (detach !== false) this._fragment.unmount(); this._fragment.destroy(); diff --git a/test/js/samples/non-imported-component/expected-bundle.js b/test/js/samples/non-imported-component/expected-bundle.js index 507161555c..37f5543dc2 100644 --- a/test/js/samples/non-imported-component/expected-bundle.js +++ b/test/js/samples/non-imported-component/expected-bundle.js @@ -28,8 +28,9 @@ function createText(data) { } function destroy(detach) { - this.destroy = this.set = this.get = noop; + this.destroy = noop; this.fire('destroy'); + this.set = this.get = noop; if (detach !== false) this._fragment.unmount(); this._fragment.destroy(); diff --git a/test/js/samples/onrender-onteardown-rewritten/expected-bundle.js b/test/js/samples/onrender-onteardown-rewritten/expected-bundle.js index df1a55ceda..e18be3c8d0 100644 --- a/test/js/samples/onrender-onteardown-rewritten/expected-bundle.js +++ b/test/js/samples/onrender-onteardown-rewritten/expected-bundle.js @@ -14,8 +14,9 @@ function assign(target) { } function destroy(detach) { - this.destroy = this.set = this.get = noop; + this.destroy = noop; this.fire('destroy'); + this.set = this.get = noop; if (detach !== false) this._fragment.unmount(); this._fragment.destroy(); diff --git a/test/js/samples/setup-method/expected-bundle.js b/test/js/samples/setup-method/expected-bundle.js index db41f989f3..14af614e67 100644 --- a/test/js/samples/setup-method/expected-bundle.js +++ b/test/js/samples/setup-method/expected-bundle.js @@ -14,8 +14,9 @@ function assign(target) { } function destroy(detach) { - this.destroy = this.set = this.get = noop; + this.destroy = noop; this.fire('destroy'); + this.set = this.get = noop; if (detach !== false) this._fragment.unmount(); this._fragment.destroy(); diff --git a/test/js/samples/use-elements-as-anchors/expected-bundle.js b/test/js/samples/use-elements-as-anchors/expected-bundle.js index bb489dfe5c..cda8dbedbb 100644 --- a/test/js/samples/use-elements-as-anchors/expected-bundle.js +++ b/test/js/samples/use-elements-as-anchors/expected-bundle.js @@ -38,8 +38,9 @@ function createComment() { } function destroy(detach) { - this.destroy = this.set = this.get = noop; + this.destroy = noop; this.fire('destroy'); + this.set = this.get = noop; if (detach !== false) this._fragment.unmount(); this._fragment.destroy(); diff --git a/test/runtime/samples/set-in-onrender/_config.js b/test/runtime/samples/set-in-oncreate/_config.js similarity index 100% rename from test/runtime/samples/set-in-onrender/_config.js rename to test/runtime/samples/set-in-oncreate/_config.js diff --git a/test/runtime/samples/set-in-onrender/main.html b/test/runtime/samples/set-in-oncreate/main.html similarity index 100% rename from test/runtime/samples/set-in-onrender/main.html rename to test/runtime/samples/set-in-oncreate/main.html diff --git a/test/runtime/samples/set-in-ondestroy/_config.js b/test/runtime/samples/set-in-ondestroy/_config.js new file mode 100644 index 0000000000..bc2212b032 --- /dev/null +++ b/test/runtime/samples/set-in-ondestroy/_config.js @@ -0,0 +1,26 @@ +export default { + 'skip-ssr': true, + + data: { + foo: 1 + }, + + test(assert, component) { + const values = []; + let valueOnDestroy; + + component.on('destroy', () => { + component.set({ foo: 2 }); + valueOnDestroy = component.get('foo'); + }); + + component.observe('foo', foo => { + values.push(foo); + }); + + component.destroy(); + + assert.deepEqual(values, [1, 2]); + assert.equal(valueOnDestroy, 2); + } +}; diff --git a/test/runtime/samples/set-in-ondestroy/main.html b/test/runtime/samples/set-in-ondestroy/main.html new file mode 100644 index 0000000000..c6cac69265 --- /dev/null +++ b/test/runtime/samples/set-in-ondestroy/main.html @@ -0,0 +1 @@ +empty