Skip to content
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

[fix]destroy empty component #7492

Merged
merged 13 commits into from Jul 4, 2022
Merged
Show file tree
Hide file tree
Changes from 11 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
2 changes: 1 addition & 1 deletion src/compiler/compile/render_dom/index.ts
Expand Up @@ -333,7 +333,7 @@ export default function dom(
// $$props arg is still needed for unknown prop check
args.push(x`$$props`);
}

// has_create_fragment is intentionally to be true in dev mode.
const has_create_fragment = component.compile_options.dev || block.has_content();
if (has_create_fragment) {
body.push(b`
Expand Down
4 changes: 3 additions & 1 deletion src/runtime/internal/transitions.ts
Expand Up @@ -79,6 +79,8 @@ export function transition_out(block: Fragment, local: 0 | 1, detach?: 0 | 1, ca
});

block.o(local);
} else if (callback) {
callback();
}
}

Expand Down Expand Up @@ -143,7 +145,7 @@ export function create_in_transition(node: Element & ElementCSSInlineStyle, fn:
return {
start() {
if (started) return;

started = true;
delete_rule(node);

Expand Down
8 changes: 8 additions & 0 deletions test/runtime/samples/empty-component-destroy/Empty.svelte
@@ -0,0 +1,8 @@

<script>
import { onDestroy } from 'svelte';
onDestroy(() => {
console.log('destroy');
});
</script>
17 changes: 17 additions & 0 deletions test/runtime/samples/empty-component-destroy/_config.js
@@ -0,0 +1,17 @@
export default {
html: `
<button>destroy component</button>
`,

async test({ assert, target, window }) {
const button = target.querySelector('button');
const event = new window.MouseEvent('click');
const messages = [];
console.log = msg => messages.push(msg);
tanhauhau marked this conversation as resolved.
Show resolved Hide resolved
await button.dispatchEvent(event);
assert.htmlEqual(target.innerHTML, `
<button>destroy component</button>
`);
assert.deepEqual(messages, ['destroy']);
}
};
8 changes: 8 additions & 0 deletions test/runtime/samples/empty-component-destroy/main.svelte
@@ -0,0 +1,8 @@
<script>
import Empty from './Empty.svelte';
let active = true;
</script>

<button on:click='{() => active = false }'>destroy component</button>

<svelte:component this={active ? Empty : null} />