Skip to content

always run onDestroy functions #3097

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 3 commits into from
Jun 24, 2019
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion src/runtime/internal/Component.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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?)
Expand Down
15 changes: 15 additions & 0 deletions test/runtime/samples/ondestroy-deep/A.svelte
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
<script>
import { onDestroy } from 'svelte';
import { destroyed } from './destroyed.js';
import B from './B.svelte';

let yes = 1;

onDestroy(() => destroyed.push('A'));
</script>

<div>
{#if yes}
<B/>
{/if}
</div>
15 changes: 15 additions & 0 deletions test/runtime/samples/ondestroy-deep/B.svelte
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
<script>
import { onDestroy } from 'svelte';
import { destroyed } from './destroyed.js';
import C from './C.svelte';

let yes = 1;

onDestroy(() => destroyed.push('B'));
</script>

<div>
{#if yes}
<C/>
{/if}
</div>
8 changes: 8 additions & 0 deletions test/runtime/samples/ondestroy-deep/C.svelte
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
<script>
import { onDestroy } from 'svelte';
import { destroyed } from './destroyed.js';

let yes = 1;

onDestroy(() => destroyed.push('C'));
</script>
10 changes: 10 additions & 0 deletions test/runtime/samples/ondestroy-deep/_config.js
Original file line number Diff line number Diff line change
@@ -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();
}
};
3 changes: 3 additions & 0 deletions test/runtime/samples/ondestroy-deep/destroyed.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
export const destroyed = [];

export const reset = () => destroyed.length = 0;
9 changes: 9 additions & 0 deletions test/runtime/samples/ondestroy-deep/main.svelte
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
<script>
import A from './A.svelte';

export let visible = true;
</script>

{#if visible}
<A/>
{/if}