From 57c6b2e94a4ee18fcabe542e81e49d5f83b8d3c0 Mon Sep 17 00:00:00 2001 From: Rich Harris Date: Mon, 24 Jun 2019 17:30:14 -0400 Subject: [PATCH 1/2] always run onDestroy functions - fixes #3058 --- src/runtime/internal/Component.ts | 2 +- test/runtime/samples/ondestroy-deep/A.svelte | 15 +++++++++++++++ test/runtime/samples/ondestroy-deep/B.svelte | 15 +++++++++++++++ test/runtime/samples/ondestroy-deep/C.svelte | 8 ++++++++ test/runtime/samples/ondestroy-deep/_config.js | 10 ++++++++++ test/runtime/samples/ondestroy-deep/destroyed.js | 3 +++ test/runtime/samples/ondestroy-deep/main.svelte | 9 +++++++++ 7 files changed, 61 insertions(+), 1 deletion(-) create mode 100644 test/runtime/samples/ondestroy-deep/A.svelte create mode 100644 test/runtime/samples/ondestroy-deep/B.svelte create mode 100644 test/runtime/samples/ondestroy-deep/C.svelte create mode 100644 test/runtime/samples/ondestroy-deep/_config.js create mode 100644 test/runtime/samples/ondestroy-deep/destroyed.js create mode 100644 test/runtime/samples/ondestroy-deep/main.svelte diff --git a/src/runtime/internal/Component.ts b/src/runtime/internal/Component.ts index 753d1c8a98..9221a683b8 100644 --- a/src/runtime/internal/Component.ts +++ b/src/runtime/internal/Component.ts @@ -54,7 +54,7 @@ export function destroy_component(component, detaching) { if (component.$$.fragment) { run_all(component.$$.on_destroy); - if (detaching) component.$$.fragment.d(1); + component.$$.fragment.d(detaching); // TODO null out other refs, including component.$$ (but need to // preserve final state?) diff --git a/test/runtime/samples/ondestroy-deep/A.svelte b/test/runtime/samples/ondestroy-deep/A.svelte new file mode 100644 index 0000000000..a1a740bc2e --- /dev/null +++ b/test/runtime/samples/ondestroy-deep/A.svelte @@ -0,0 +1,15 @@ + + +
+ {#if yes} + + {/if} +
\ No newline at end of file diff --git a/test/runtime/samples/ondestroy-deep/B.svelte b/test/runtime/samples/ondestroy-deep/B.svelte new file mode 100644 index 0000000000..78b042f2d6 --- /dev/null +++ b/test/runtime/samples/ondestroy-deep/B.svelte @@ -0,0 +1,15 @@ + + +
+ {#if yes} + + {/if} +
\ No newline at end of file diff --git a/test/runtime/samples/ondestroy-deep/C.svelte b/test/runtime/samples/ondestroy-deep/C.svelte new file mode 100644 index 0000000000..27f33c93fc --- /dev/null +++ b/test/runtime/samples/ondestroy-deep/C.svelte @@ -0,0 +1,8 @@ + \ No newline at end of file diff --git a/test/runtime/samples/ondestroy-deep/_config.js b/test/runtime/samples/ondestroy-deep/_config.js new file mode 100644 index 0000000000..4431a2e163 --- /dev/null +++ b/test/runtime/samples/ondestroy-deep/_config.js @@ -0,0 +1,10 @@ +import { destroyed, reset } from './destroyed.js'; + +export default { + test({ assert, component }) { + component.visible = false; + assert.deepEqual(destroyed, ['A', 'B', 'C']); + + reset(); + } +}; \ No newline at end of file diff --git a/test/runtime/samples/ondestroy-deep/destroyed.js b/test/runtime/samples/ondestroy-deep/destroyed.js new file mode 100644 index 0000000000..4a99a931d4 --- /dev/null +++ b/test/runtime/samples/ondestroy-deep/destroyed.js @@ -0,0 +1,3 @@ +export let destroyed = []; + +export const reset = () => destroyed.length = 0; \ No newline at end of file diff --git a/test/runtime/samples/ondestroy-deep/main.svelte b/test/runtime/samples/ondestroy-deep/main.svelte new file mode 100644 index 0000000000..d584dc1b85 --- /dev/null +++ b/test/runtime/samples/ondestroy-deep/main.svelte @@ -0,0 +1,9 @@ + + +{#if visible} + +{/if} \ No newline at end of file From 2d1ecd454485ab21958a3972cde3c8fbfb922efc Mon Sep 17 00:00:00 2001 From: Rich Harris Date: Mon, 24 Jun 2019 17:48:42 -0400 Subject: [PATCH 2/2] lint --- test/runtime/samples/ondestroy-deep/destroyed.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/test/runtime/samples/ondestroy-deep/destroyed.js b/test/runtime/samples/ondestroy-deep/destroyed.js index 4a99a931d4..fe05c1d241 100644 --- a/test/runtime/samples/ondestroy-deep/destroyed.js +++ b/test/runtime/samples/ondestroy-deep/destroyed.js @@ -1,3 +1,3 @@ -export let destroyed = []; +export const destroyed = []; export const reset = () => destroyed.length = 0; \ No newline at end of file