Skip to content

Commit 2536bd2

Browse files
authored
Merge pull request #3172 from sveltejs/gh-3113
prevent dynamic components being detached twice
2 parents 7e01c3c + af0d9ed commit 2536bd2

File tree

10 files changed

+22
-10
lines changed

10 files changed

+22
-10
lines changed

src/compiler/compile/render_dom/wrappers/EachBlock.ts

+1-1
Original file line numberDiff line numberDiff line change
@@ -493,7 +493,7 @@ export default class EachBlockWrapper extends Wrapper {
493493
const out = block.get_unique_name('out');
494494

495495
block.builders.init.add_block(deindent`
496-
const ${out} = i => @transition_out(${iterations}[i], 1, () => {
496+
const ${out} = i => @transition_out(${iterations}[i], 1, 1, () => {
497497
${iterations}[i] = null;
498498
});
499499
`);

src/compiler/compile/render_dom/wrappers/IfBlock.ts

+2-2
Original file line numberDiff line numberDiff line change
@@ -326,7 +326,7 @@ export default class IfBlockWrapper extends Wrapper {
326326

327327
const destroy_old_block = deindent`
328328
@group_outros();
329-
@transition_out(${if_blocks}[${previous_block_index}], 1, () => {
329+
@transition_out(${if_blocks}[${previous_block_index}], 1, 1, () => {
330330
${if_blocks}[${previous_block_index}] = null;
331331
});
332332
@check_outros();
@@ -439,7 +439,7 @@ export default class IfBlockWrapper extends Wrapper {
439439
${enter}
440440
} else if (${name}) {
441441
@group_outros();
442-
@transition_out(${name}, 1, () => {
442+
@transition_out(${name}, 1, 1, () => {
443443
${name} = null;
444444
});
445445
@check_outros();

src/compiler/compile/render_dom/wrappers/InlineComponent/index.ts

+2-2
Original file line numberDiff line numberDiff line change
@@ -388,8 +388,8 @@ export default class InlineComponentWrapper extends Wrapper {
388388
if (${name}) {
389389
@group_outros();
390390
const old_component = ${name};
391-
@transition_out(old_component.$$.fragment, 1, () => {
392-
@destroy_component(old_component);
391+
@transition_out(old_component.$$.fragment, 1, 0, () => {
392+
@destroy_component(old_component, 1);
393393
});
394394
@check_outros();
395395
}

src/runtime/internal/await_block.ts

+1-1
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,7 @@ export function handle_promise(promise, info) {
1818
info.blocks.forEach((block, i) => {
1919
if (i !== index && block) {
2020
group_outros();
21-
transition_out(block, 1, () => {
21+
transition_out(block, 1, 1, () => {
2222
info.blocks[i] = null;
2323
});
2424
check_outros();

src/runtime/internal/keyed_each.ts

+1-1
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@ export function destroy_block(block, lookup) {
66
}
77

88
export function outro_and_destroy_block(block, lookup) {
9-
transition_out(block, 1, () => {
9+
transition_out(block, 1, 1, () => {
1010
lookup.delete(block.key);
1111
});
1212
}

src/runtime/internal/transitions.ts

+2-2
Original file line numberDiff line numberDiff line change
@@ -46,15 +46,15 @@ export function transition_in(block, local?: 0 | 1) {
4646
}
4747
}
4848

49-
export function transition_out(block, local: 0 | 1, callback) {
49+
export function transition_out(block, local: 0 | 1, detach: 0 | 1, callback) {
5050
if (block && block.o) {
5151
if (outroing.has(block)) return;
5252
outroing.add(block);
5353

5454
outros.callbacks.push(() => {
5555
outroing.delete(block);
5656
if (callback) {
57-
block.d(1);
57+
if (detach) block.d(1);
5858
callback();
5959
}
6060
});

test/js/samples/transition-repeated-outro/expected.js

+1-1
Original file line numberDiff line numberDiff line change
@@ -81,7 +81,7 @@ function create_fragment(ctx) {
8181
}
8282
} else if (if_block) {
8383
group_outros();
84-
transition_out(if_block, 1, () => {
84+
transition_out(if_block, 1, 1, () => {
8585
if_block = null;
8686
});
8787
check_outros();
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
{#await null}{/await}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
export default {
2+
test({ component }) {
3+
component.flag = false;
4+
}
5+
};
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
<script>
2+
export let flag = true;
3+
import Widget from './Widget.svelte';
4+
</script>
5+
6+
<svelte:component this={flag && Widget}/>

0 commit comments

Comments
 (0)