From 85e25a957ddb3b6100db4d1d9e63ee2b745e86d1 Mon Sep 17 00:00:00 2001 From: Rich Harris Date: Tue, 9 Jul 2019 12:20:13 -0400 Subject: [PATCH 1/3] add test from gh-2086 --- .../head-detached-in-dynamic-component/A.svelte | 5 +++++ .../head-detached-in-dynamic-component/B.svelte | 5 +++++ .../head-detached-in-dynamic-component/_config.js | 15 +++++++++++++++ .../main.svelte | 8 ++++++++ 4 files changed, 33 insertions(+) create mode 100644 test/runtime/samples/head-detached-in-dynamic-component/A.svelte create mode 100644 test/runtime/samples/head-detached-in-dynamic-component/B.svelte create mode 100644 test/runtime/samples/head-detached-in-dynamic-component/_config.js create mode 100644 test/runtime/samples/head-detached-in-dynamic-component/main.svelte diff --git a/test/runtime/samples/head-detached-in-dynamic-component/A.svelte b/test/runtime/samples/head-detached-in-dynamic-component/A.svelte new file mode 100644 index 00000000000..f05488e3e4e --- /dev/null +++ b/test/runtime/samples/head-detached-in-dynamic-component/A.svelte @@ -0,0 +1,5 @@ + + + + +A \ No newline at end of file diff --git a/test/runtime/samples/head-detached-in-dynamic-component/B.svelte b/test/runtime/samples/head-detached-in-dynamic-component/B.svelte new file mode 100644 index 00000000000..943b307cc30 --- /dev/null +++ b/test/runtime/samples/head-detached-in-dynamic-component/B.svelte @@ -0,0 +1,5 @@ + + + + +B \ No newline at end of file diff --git a/test/runtime/samples/head-detached-in-dynamic-component/_config.js b/test/runtime/samples/head-detached-in-dynamic-component/_config.js new file mode 100644 index 00000000000..e18589e10e1 --- /dev/null +++ b/test/runtime/samples/head-detached-in-dynamic-component/_config.js @@ -0,0 +1,15 @@ +export default { + html: ` + A + `, + + test({ assert, component, window }) { + component.x = false; + + const meta = window.document.querySelectorAll('meta'); + + assert.equal(meta.length, 1); + assert.equal(meta[0].name, 'description'); + assert.equal(meta[0].content, 'B'); + } +}; diff --git a/test/runtime/samples/head-detached-in-dynamic-component/main.svelte b/test/runtime/samples/head-detached-in-dynamic-component/main.svelte new file mode 100644 index 00000000000..e4acd7737ad --- /dev/null +++ b/test/runtime/samples/head-detached-in-dynamic-component/main.svelte @@ -0,0 +1,8 @@ + + + \ No newline at end of file From 65b28ed0f5df4bcdbf7eb0a6d8cae4518600b284 Mon Sep 17 00:00:00 2001 From: Rich Harris Date: Tue, 9 Jul 2019 12:31:38 -0400 Subject: [PATCH 2/3] new failing test for #2086 --- .../samples/each-block-keyed-nested/Child.svelte | 5 +++++ .../samples/each-block-keyed-nested/_config.js | 16 ++++++++++++++++ .../samples/each-block-keyed-nested/main.svelte | 16 ++++++++++++++++ 3 files changed, 37 insertions(+) create mode 100644 test/runtime/samples/each-block-keyed-nested/Child.svelte create mode 100644 test/runtime/samples/each-block-keyed-nested/_config.js create mode 100644 test/runtime/samples/each-block-keyed-nested/main.svelte diff --git a/test/runtime/samples/each-block-keyed-nested/Child.svelte b/test/runtime/samples/each-block-keyed-nested/Child.svelte new file mode 100644 index 00000000000..e7ed7268503 --- /dev/null +++ b/test/runtime/samples/each-block-keyed-nested/Child.svelte @@ -0,0 +1,5 @@ + + +{id} \ No newline at end of file diff --git a/test/runtime/samples/each-block-keyed-nested/_config.js b/test/runtime/samples/each-block-keyed-nested/_config.js new file mode 100644 index 00000000000..b45716be4ff --- /dev/null +++ b/test/runtime/samples/each-block-keyed-nested/_config.js @@ -0,0 +1,16 @@ +export default { + html: ` + 1 + `, + + test({ assert, component, target }) { + component.desks = [ + { + id: 1, + teams: [{ id: 2 }] + } + ]; + + assert.htmlEqual(target.innerHTML, '2'); + } +}; diff --git a/test/runtime/samples/each-block-keyed-nested/main.svelte b/test/runtime/samples/each-block-keyed-nested/main.svelte new file mode 100644 index 00000000000..86f665a5e78 --- /dev/null +++ b/test/runtime/samples/each-block-keyed-nested/main.svelte @@ -0,0 +1,16 @@ + + +{#each desks as desk (desk.id)} + {#each desk.teams as team (team.id)} + + {/each} +{/each} \ No newline at end of file From 2f08e34b41317619f9bc7bf6bc2418123fb06829 Mon Sep 17 00:00:00 2001 From: Rich Harris Date: Tue, 9 Jul 2019 14:04:13 -0400 Subject: [PATCH 3/3] prevent outro groups getting muddled up - fixes #2086 --- src/runtime/internal/transitions.ts | 22 ++++++++++--------- .../each-block-keyed-nested/_config.js | 4 ++-- 2 files changed, 14 insertions(+), 12 deletions(-) diff --git a/src/runtime/internal/transitions.ts b/src/runtime/internal/transitions.ts index 91f243b4d6e..e3a0b44fc49 100644 --- a/src/runtime/internal/transitions.ts +++ b/src/runtime/internal/transitions.ts @@ -28,15 +28,17 @@ let outros; export function group_outros() { outros = { - remaining: 0, - callbacks: [] + r: 0, // remaining outros + c: [], // callbacks + p: outros // parent group }; } export function check_outros() { - if (!outros.remaining) { - run_all(outros.callbacks); + if (!outros.r) { + run_all(outros.c); } + outros = outros.p; } export function transition_in(block, local?: 0 | 1) { @@ -51,7 +53,7 @@ export function transition_out(block, local: 0 | 1, detach: 0 | 1, callback) { if (outroing.has(block)) return; outroing.add(block); - outros.callbacks.push(() => { + outros.c.push(() => { outroing.delete(block); if (callback) { if (detach) block.d(1); @@ -153,7 +155,7 @@ export function create_out_transition(node: Element & ElementCSSInlineStyle, fn: const group = outros; - group.remaining += 1; + group.r += 1; function go() { const { @@ -178,10 +180,10 @@ export function create_out_transition(node: Element & ElementCSSInlineStyle, fn: dispatch(node, false, 'end'); - if (!--group.remaining) { + if (!--group.r) { // this will result in `end()` being called, // so we don't need to clean up here - run_all(group.callbacks); + run_all(group.c); } return false; @@ -266,7 +268,7 @@ export function create_bidirectional_transition(node: Element & ElementCSSInline if (!b) { // @ts-ignore todo: improve typings program.group = outros; - outros.remaining += 1; + outros.r += 1; } if (running_program) { @@ -309,7 +311,7 @@ export function create_bidirectional_transition(node: Element & ElementCSSInline clear_animation(); } else { // outro — needs to be coordinated - if (!--running_program.group.remaining) run_all(running_program.group.callbacks); + if (!--running_program.group.r) run_all(running_program.group.c); } } diff --git a/test/runtime/samples/each-block-keyed-nested/_config.js b/test/runtime/samples/each-block-keyed-nested/_config.js index b45716be4ff..3440874a8cc 100644 --- a/test/runtime/samples/each-block-keyed-nested/_config.js +++ b/test/runtime/samples/each-block-keyed-nested/_config.js @@ -7,10 +7,10 @@ export default { component.desks = [ { id: 1, - teams: [{ id: 2 }] + teams: [] } ]; - assert.htmlEqual(target.innerHTML, '2'); + assert.htmlEqual(target.innerHTML, ''); } };