prevent await block mounting inside removed if block - fixes #1496

pull/3142/head
Richard Harris 6 years ago
parent 220515b605
commit b7ba0d69ee

@ -137,6 +137,7 @@ export default class AwaitBlockWrapper extends Wrapper {
const info_props = [ const info_props = [
'ctx', 'ctx',
'current: null', 'current: null',
'token: null',
this.pending.block.name && `pending: ${this.pending.block.name}`, this.pending.block.name && `pending: ${this.pending.block.name}`,
this.then.block.name && `then: ${this.then.block.name}`, this.then.block.name && `then: ${this.then.block.name}`,
this.catch.block.name && `catch: ${this.catch.block.name}`, this.catch.block.name && `catch: ${this.catch.block.name}`,
@ -223,6 +224,7 @@ export default class AwaitBlockWrapper extends Wrapper {
block.builders.destroy.add_block(deindent` block.builders.destroy.add_block(deindent`
${info}.block.d(${parent_node ? '' : 'detaching'}); ${info}.block.d(${parent_node ? '' : 'detaching'});
${info}.token = null;
${info} = null; ${info} = null;
`); `);

@ -21,6 +21,11 @@ let compile = null;
const sveltePath = process.cwd().split('\\').join('/'); const sveltePath = process.cwd().split('\\').join('/');
let unhandled_rejection = false;
process.on('unhandledRejection', err => {
unhandled_rejection = err;
});
describe("runtime", () => { describe("runtime", () => {
before(() => { before(() => {
svelte = loadSvelte(false); svelte = loadSvelte(false);
@ -60,6 +65,8 @@ describe("runtime", () => {
throw new Error('skipping test, already failed'); throw new Error('skipping test, already failed');
} }
unhandled_rejection = null;
compile = (config.preserveIdentifiers ? svelte : svelte$).compile; compile = (config.preserveIdentifiers ? svelte : svelte$).compile;
const cwd = path.resolve(`test/runtime/samples/${dir}`); const cwd = path.resolve(`test/runtime/samples/${dir}`);
@ -165,10 +172,18 @@ describe("runtime", () => {
raf raf
})).then(() => { })).then(() => {
component.$destroy(); component.$destroy();
if (unhandled_rejection) {
throw unhandled_rejection;
}
}); });
} else { } else {
component.$destroy(); component.$destroy();
assert.htmlEqual(target.innerHTML, ""); assert.htmlEqual(target.innerHTML, "");
if (unhandled_rejection) {
throw unhandled_rejection;
}
} }
}) })
.catch(err => { .catch(err => {

@ -0,0 +1,22 @@
let fulfil;
const promise = new Promise(f => {
fulfil = f;
});
export default {
props: {
promise
},
html: ``,
async test({ assert, component, target }) {
component.condition = false;
fulfil();
await new Promise(f => setTimeout(f, 0));
assert.htmlEqual(target.innerHTML, ``);
}
};

@ -0,0 +1,8 @@
<script>
export let promise;
export let condition = true;
</script>
{#if condition}
{#await promise then _}hello{/await}
{/if}
Loading…
Cancel
Save