From f4ca063c85e491b75d162f429ad243b6f443db13 Mon Sep 17 00:00:00 2001 From: Richard Harris Date: Wed, 3 Jul 2019 20:13:22 -0400 Subject: [PATCH] prevent dynamic components being detached twice - fixes #3113 --- src/compiler/compile/render_dom/wrappers/EachBlock.ts | 2 +- src/compiler/compile/render_dom/wrappers/IfBlock.ts | 4 ++-- .../compile/render_dom/wrappers/InlineComponent/index.ts | 4 ++-- src/runtime/internal/await_block.ts | 2 +- src/runtime/internal/keyed_each.ts | 2 +- src/runtime/internal/transitions.ts | 4 ++-- test/js/samples/transition-repeated-outro/expected.js | 2 +- .../samples/await-in-dynamic-component/Widget.svelte | 1 + test/runtime/samples/await-in-dynamic-component/_config.js | 5 +++++ test/runtime/samples/await-in-dynamic-component/main.svelte | 6 ++++++ 10 files changed, 22 insertions(+), 10 deletions(-) create mode 100644 test/runtime/samples/await-in-dynamic-component/Widget.svelte create mode 100644 test/runtime/samples/await-in-dynamic-component/_config.js create mode 100644 test/runtime/samples/await-in-dynamic-component/main.svelte diff --git a/src/compiler/compile/render_dom/wrappers/EachBlock.ts b/src/compiler/compile/render_dom/wrappers/EachBlock.ts index 242d14b7932e..42792efce714 100644 --- a/src/compiler/compile/render_dom/wrappers/EachBlock.ts +++ b/src/compiler/compile/render_dom/wrappers/EachBlock.ts @@ -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; }); `); diff --git a/src/compiler/compile/render_dom/wrappers/IfBlock.ts b/src/compiler/compile/render_dom/wrappers/IfBlock.ts index a783364d030b..fe870df862d1 100644 --- a/src/compiler/compile/render_dom/wrappers/IfBlock.ts +++ b/src/compiler/compile/render_dom/wrappers/IfBlock.ts @@ -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(); @@ -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(); diff --git a/src/compiler/compile/render_dom/wrappers/InlineComponent/index.ts b/src/compiler/compile/render_dom/wrappers/InlineComponent/index.ts index 82e3fcd56b93..8f6aafd5db57 100644 --- a/src/compiler/compile/render_dom/wrappers/InlineComponent/index.ts +++ b/src/compiler/compile/render_dom/wrappers/InlineComponent/index.ts @@ -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(); } diff --git a/src/runtime/internal/await_block.ts b/src/runtime/internal/await_block.ts index a8cce36c3f34..3834ff7c313d 100644 --- a/src/runtime/internal/await_block.ts +++ b/src/runtime/internal/await_block.ts @@ -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(); diff --git a/src/runtime/internal/keyed_each.ts b/src/runtime/internal/keyed_each.ts index e18ae6177051..76708c93dbd4 100644 --- a/src/runtime/internal/keyed_each.ts +++ b/src/runtime/internal/keyed_each.ts @@ -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); }); } diff --git a/src/runtime/internal/transitions.ts b/src/runtime/internal/transitions.ts index bbb24ba9ee64..91f243b4d6e8 100644 --- a/src/runtime/internal/transitions.ts +++ b/src/runtime/internal/transitions.ts @@ -46,7 +46,7 @@ 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); @@ -54,7 +54,7 @@ export function transition_out(block, local: 0 | 1, callback) { outros.callbacks.push(() => { outroing.delete(block); if (callback) { - block.d(1); + if (detach) block.d(1); callback(); } }); diff --git a/test/js/samples/transition-repeated-outro/expected.js b/test/js/samples/transition-repeated-outro/expected.js index 959bd4720151..8543d0029b00 100644 --- a/test/js/samples/transition-repeated-outro/expected.js +++ b/test/js/samples/transition-repeated-outro/expected.js @@ -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(); diff --git a/test/runtime/samples/await-in-dynamic-component/Widget.svelte b/test/runtime/samples/await-in-dynamic-component/Widget.svelte new file mode 100644 index 000000000000..78118e944d22 --- /dev/null +++ b/test/runtime/samples/await-in-dynamic-component/Widget.svelte @@ -0,0 +1 @@ +{#await null}{/await} \ No newline at end of file diff --git a/test/runtime/samples/await-in-dynamic-component/_config.js b/test/runtime/samples/await-in-dynamic-component/_config.js new file mode 100644 index 000000000000..797298c55492 --- /dev/null +++ b/test/runtime/samples/await-in-dynamic-component/_config.js @@ -0,0 +1,5 @@ +export default { + test({ component }) { + component.flag = false; + } +}; \ No newline at end of file diff --git a/test/runtime/samples/await-in-dynamic-component/main.svelte b/test/runtime/samples/await-in-dynamic-component/main.svelte new file mode 100644 index 000000000000..c395cb449957 --- /dev/null +++ b/test/runtime/samples/await-in-dynamic-component/main.svelte @@ -0,0 +1,6 @@ + + + \ No newline at end of file