Skip to content

Commit 283152f

Browse files
authored
Merge pull request #3209 from sveltejs/gh-2086-2
Prevent outro callback corruption
2 parents 1e4c1d1 + 2f08e34 commit 283152f

File tree

8 files changed

+82
-10
lines changed

8 files changed

+82
-10
lines changed

src/runtime/internal/transitions.ts

+12-10
Original file line numberDiff line numberDiff line change
@@ -28,15 +28,17 @@ let outros;
2828

2929
export function group_outros() {
3030
outros = {
31-
remaining: 0,
32-
callbacks: []
31+
r: 0, // remaining outros
32+
c: [], // callbacks
33+
p: outros // parent group
3334
};
3435
}
3536

3637
export function check_outros() {
37-
if (!outros.remaining) {
38-
run_all(outros.callbacks);
38+
if (!outros.r) {
39+
run_all(outros.c);
3940
}
41+
outros = outros.p;
4042
}
4143

4244
export function transition_in(block, local?: 0 | 1) {
@@ -51,7 +53,7 @@ export function transition_out(block, local: 0 | 1, detach: 0 | 1, callback) {
5153
if (outroing.has(block)) return;
5254
outroing.add(block);
5355

54-
outros.callbacks.push(() => {
56+
outros.c.push(() => {
5557
outroing.delete(block);
5658
if (callback) {
5759
if (detach) block.d(1);
@@ -153,7 +155,7 @@ export function create_out_transition(node: Element & ElementCSSInlineStyle, fn:
153155

154156
const group = outros;
155157

156-
group.remaining += 1;
158+
group.r += 1;
157159

158160
function go() {
159161
const {
@@ -178,10 +180,10 @@ export function create_out_transition(node: Element & ElementCSSInlineStyle, fn:
178180

179181
dispatch(node, false, 'end');
180182

181-
if (!--group.remaining) {
183+
if (!--group.r) {
182184
// this will result in `end()` being called,
183185
// so we don't need to clean up here
184-
run_all(group.callbacks);
186+
run_all(group.c);
185187
}
186188

187189
return false;
@@ -266,7 +268,7 @@ export function create_bidirectional_transition(node: Element & ElementCSSInline
266268
if (!b) {
267269
// @ts-ignore todo: improve typings
268270
program.group = outros;
269-
outros.remaining += 1;
271+
outros.r += 1;
270272
}
271273

272274
if (running_program) {
@@ -309,7 +311,7 @@ export function create_bidirectional_transition(node: Element & ElementCSSInline
309311
clear_animation();
310312
} else {
311313
// outro — needs to be coordinated
312-
if (!--running_program.group.remaining) run_all(running_program.group.callbacks);
314+
if (!--running_program.group.r) run_all(running_program.group.c);
313315
}
314316
}
315317

Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
<script>
2+
export let id;
3+
</script>
4+
5+
{id}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
export default {
2+
html: `
3+
1
4+
`,
5+
6+
test({ assert, component, target }) {
7+
component.desks = [
8+
{
9+
id: 1,
10+
teams: []
11+
}
12+
];
13+
14+
assert.htmlEqual(target.innerHTML, '');
15+
}
16+
};
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
<script>
2+
import Child from './Child.svelte';
3+
4+
export let desks = [
5+
{
6+
id: 1,
7+
teams: [{ id: 1 }]
8+
}
9+
];
10+
</script>
11+
12+
{#each desks as desk (desk.id)}
13+
{#each desk.teams as team (team.id)}
14+
<Child id={team.id} />
15+
{/each}
16+
{/each}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
<svelte:head>
2+
<meta name="description" content="A"/>
3+
</svelte:head>
4+
5+
A
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
<svelte:head>
2+
<meta name="description" content="B"/>
3+
</svelte:head>
4+
5+
B
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
export default {
2+
html: `
3+
A
4+
`,
5+
6+
test({ assert, component, window }) {
7+
component.x = false;
8+
9+
const meta = window.document.querySelectorAll('meta');
10+
11+
assert.equal(meta.length, 1);
12+
assert.equal(meta[0].name, 'description');
13+
assert.equal(meta[0].content, 'B');
14+
}
15+
};
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
<script>
2+
import A from './A.svelte';
3+
import B from './B.svelte';
4+
5+
export let x = true;
6+
</script>
7+
8+
<svelte:component this="{x ? A : B}"/>

0 commit comments

Comments
 (0)