From 0e90ddcb0af192b3947e52e20d60ef0b3755fff1 Mon Sep 17 00:00:00 2001 From: Rich Harris Date: Mon, 24 Jun 2019 17:30:14 -0400 Subject: [PATCH] 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 753d1c8a9872..9221a683b851 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 000000000000..a1a740bc2ec2 --- /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 000000000000..78b042f2d678 --- /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 000000000000..27f33c93fcca --- /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 000000000000..4431a2e16317 --- /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 000000000000..4a99a931d487 --- /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 000000000000..d584dc1b8553 --- /dev/null +++ b/test/runtime/samples/ondestroy-deep/main.svelte @@ -0,0 +1,9 @@ + + +{#if visible} + +{/if} \ No newline at end of file