Skip to content

Commit

Permalink
prevent outro groups getting muddled up - fixes #2086
Browse files Browse the repository at this point in the history
  • Loading branch information
Rich-Harris committed Jul 9, 2019
1 parent 65b28ed commit 2f08e34
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 12 deletions.
22 changes: 12 additions & 10 deletions src/runtime/internal/transitions.ts
Expand Up @@ -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) {
Expand All @@ -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);
Expand Down Expand Up @@ -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 {
Expand All @@ -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;
Expand Down Expand Up @@ -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) {
Expand Down Expand Up @@ -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);
}
}

Expand Down
4 changes: 2 additions & 2 deletions test/runtime/samples/each-block-keyed-nested/_config.js
Expand Up @@ -7,10 +7,10 @@ export default {
component.desks = [
{
id: 1,
teams: [{ id: 2 }]
teams: []
}
];

assert.htmlEqual(target.innerHTML, '2');
assert.htmlEqual(target.innerHTML, '');
}
};

0 comments on commit 2f08e34

Please sign in to comment.