Skip to content

Commit

Permalink
prevent dynamic components being detached twice - fixes #3113
Browse files Browse the repository at this point in the history
  • Loading branch information
Rich-Harris committed Jul 4, 2019
1 parent 943c048 commit f4ca063
Show file tree
Hide file tree
Showing 10 changed files with 22 additions and 10 deletions.
2 changes: 1 addition & 1 deletion src/compiler/compile/render_dom/wrappers/EachBlock.ts
Original file line number Diff line number Diff line change
Expand Up @@ -493,7 +493,7 @@ export default class EachBlockWrapper extends Wrapper {
const out = block.get_unique_name('out');

block.builders.init.add_block(deindent`
const ${out} = i => @transition_out(${iterations}[i], 1, () => {
const ${out} = i => @transition_out(${iterations}[i], 1, 1, () => {
${iterations}[i] = null;
});
`);
Expand Down
4 changes: 2 additions & 2 deletions src/compiler/compile/render_dom/wrappers/IfBlock.ts
Original file line number Diff line number Diff line change
Expand Up @@ -326,7 +326,7 @@ export default class IfBlockWrapper extends Wrapper {

const destroy_old_block = deindent`
@group_outros();
@transition_out(${if_blocks}[${previous_block_index}], 1, () => {
@transition_out(${if_blocks}[${previous_block_index}], 1, 1, () => {
${if_blocks}[${previous_block_index}] = null;
});
@check_outros();
Expand Down Expand Up @@ -439,7 +439,7 @@ export default class IfBlockWrapper extends Wrapper {
${enter}
} else if (${name}) {
@group_outros();
@transition_out(${name}, 1, () => {
@transition_out(${name}, 1, 1, () => {
${name} = null;
});
@check_outros();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -388,8 +388,8 @@ export default class InlineComponentWrapper extends Wrapper {
if (${name}) {
@group_outros();
const old_component = ${name};
@transition_out(old_component.$$.fragment, 1, () => {
@destroy_component(old_component);
@transition_out(old_component.$$.fragment, 1, 0, () => {
@destroy_component(old_component, 1);
});
@check_outros();
}
Expand Down
2 changes: 1 addition & 1 deletion src/runtime/internal/await_block.ts
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ export function handle_promise(promise, info) {
info.blocks.forEach((block, i) => {
if (i !== index && block) {
group_outros();
transition_out(block, 1, () => {
transition_out(block, 1, 1, () => {
info.blocks[i] = null;
});
check_outros();
Expand Down
2 changes: 1 addition & 1 deletion src/runtime/internal/keyed_each.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ export function destroy_block(block, lookup) {
}

export function outro_and_destroy_block(block, lookup) {
transition_out(block, 1, () => {
transition_out(block, 1, 1, () => {
lookup.delete(block.key);
});
}
Expand Down
4 changes: 2 additions & 2 deletions src/runtime/internal/transitions.ts
Original file line number Diff line number Diff line change
Expand Up @@ -46,15 +46,15 @@ export function transition_in(block, local?: 0 | 1) {
}
}

export function transition_out(block, local: 0 | 1, callback) {
export function transition_out(block, local: 0 | 1, detach: 0 | 1, callback) {
if (block && block.o) {
if (outroing.has(block)) return;
outroing.add(block);

outros.callbacks.push(() => {
outroing.delete(block);
if (callback) {
block.d(1);
if (detach) block.d(1);
callback();
}
});
Expand Down
2 changes: 1 addition & 1 deletion test/js/samples/transition-repeated-outro/expected.js
Original file line number Diff line number Diff line change
Expand Up @@ -81,7 +81,7 @@ function create_fragment(ctx) {
}
} else if (if_block) {
group_outros();
transition_out(if_block, 1, () => {
transition_out(if_block, 1, 1, () => {
if_block = null;
});
check_outros();
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
{#await null}{/await}
5 changes: 5 additions & 0 deletions test/runtime/samples/await-in-dynamic-component/_config.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
export default {
test({ component }) {
component.flag = false;
}
};
6 changes: 6 additions & 0 deletions test/runtime/samples/await-in-dynamic-component/main.svelte
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
<script>
export let flag = true;
import Widget from './Widget.svelte';
</script>

<svelte:component this={flag && Widget}/>

0 comments on commit f4ca063

Please sign in to comment.