Skip to content

Commit b7ba0d6

Browse files
committed
prevent await block mounting inside removed if block - fixes #1496
1 parent 220515b commit b7ba0d6

File tree

4 files changed

+47
-0
lines changed

4 files changed

+47
-0
lines changed

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

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -137,6 +137,7 @@ export default class AwaitBlockWrapper extends Wrapper {
137137
const info_props = [
138138
'ctx',
139139
'current: null',
140+
'token: null',
140141
this.pending.block.name && `pending: ${this.pending.block.name}`,
141142
this.then.block.name && `then: ${this.then.block.name}`,
142143
this.catch.block.name && `catch: ${this.catch.block.name}`,
@@ -223,6 +224,7 @@ export default class AwaitBlockWrapper extends Wrapper {
223224

224225
block.builders.destroy.add_block(deindent`
225226
${info}.block.d(${parent_node ? '' : 'detaching'});
227+
${info}.token = null;
226228
${info} = null;
227229
`);
228230

test/runtime/index.js

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,11 @@ let compile = null;
2121

2222
const sveltePath = process.cwd().split('\\').join('/');
2323

24+
let unhandled_rejection = false;
25+
process.on('unhandledRejection', err => {
26+
unhandled_rejection = err;
27+
});
28+
2429
describe("runtime", () => {
2530
before(() => {
2631
svelte = loadSvelte(false);
@@ -60,6 +65,8 @@ describe("runtime", () => {
6065
throw new Error('skipping test, already failed');
6166
}
6267

68+
unhandled_rejection = null;
69+
6370
compile = (config.preserveIdentifiers ? svelte : svelte$).compile;
6471

6572
const cwd = path.resolve(`test/runtime/samples/${dir}`);
@@ -165,10 +172,18 @@ describe("runtime", () => {
165172
raf
166173
})).then(() => {
167174
component.$destroy();
175+
176+
if (unhandled_rejection) {
177+
throw unhandled_rejection;
178+
}
168179
});
169180
} else {
170181
component.$destroy();
171182
assert.htmlEqual(target.innerHTML, "");
183+
184+
if (unhandled_rejection) {
185+
throw unhandled_rejection;
186+
}
172187
}
173188
})
174189
.catch(err => {
Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,22 @@
1+
let fulfil;
2+
3+
const promise = new Promise(f => {
4+
fulfil = f;
5+
});
6+
7+
export default {
8+
props: {
9+
promise
10+
},
11+
12+
html: ``,
13+
14+
async test({ assert, component, target }) {
15+
component.condition = false;
16+
17+
fulfil();
18+
await new Promise(f => setTimeout(f, 0));
19+
20+
assert.htmlEqual(target.innerHTML, ``);
21+
}
22+
};
Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
<script>
2+
export let promise;
3+
export let condition = true;
4+
</script>
5+
6+
{#if condition}
7+
{#await promise then _}hello{/await}
8+
{/if}

0 commit comments

Comments
 (0)