diff --git a/src/compiler/compile/render_dom/wrappers/AwaitBlock.ts b/src/compiler/compile/render_dom/wrappers/AwaitBlock.ts index ff835ddef6..354143feab 100644 --- a/src/compiler/compile/render_dom/wrappers/AwaitBlock.ts +++ b/src/compiler/compile/render_dom/wrappers/AwaitBlock.ts @@ -188,29 +188,35 @@ export default class AwaitBlockWrapper extends Wrapper { conditions.push( `(${dependencies.map(dep => `'${dep}' in changed`).join(' || ')})` ); - } - conditions.push( - `${promise} !== (${promise} = ${snippet})`, - `@handle_promise(${promise}, ${info})` - ); + conditions.push( + `${promise} !== (${promise} = ${snippet})`, + `@handle_promise(${promise}, ${info})` + ); - block.builders.update.add_line( - `${info}.ctx = ctx;` - ); + block.builders.update.add_line( + `${info}.ctx = ctx;` + ); - if (this.pending.block.has_update_method) { - block.builders.update.add_block(deindent` - if (${conditions.join(' && ')}) { - // nothing - } else { - ${info}.block.p(changed, @assign(@assign({}, ctx), ${info}.resolved)); - } - `); + if (this.pending.block.has_update_method) { + block.builders.update.add_block(deindent` + if (${conditions.join(' && ')}) { + // nothing + } else { + ${info}.block.p(changed, @assign(@assign({}, ctx), ${info}.resolved)); + } + `); + } else { + block.builders.update.add_block(deindent` + ${conditions.join(' && ')} + `); + } } else { - block.builders.update.add_block(deindent` - ${conditions.join(' && ')} - `); + if (this.pending.block.has_update_method) { + block.builders.update.add_block(deindent` + ${info}.block.p(changed, @assign(@assign({}, ctx), ${info}.resolved)); + `); + } } if (this.pending.block.has_outro_method) { diff --git a/test/runtime/samples/await-conservative-update/_config.js b/test/runtime/samples/await-conservative-update/_config.js new file mode 100644 index 0000000000..4e81ff8e37 --- /dev/null +++ b/test/runtime/samples/await-conservative-update/_config.js @@ -0,0 +1,16 @@ +import { sleep } from './sleep.js'; + +export default { + html: ` +

loading...

+ `, + + test({ assert, component, target }) { + return sleep(50).then(() => { + assert.htmlEqual(target.innerHTML, ` +

the answer is 42

+

count: 1

+ `); + }); + } +}; \ No newline at end of file diff --git a/test/runtime/samples/await-conservative-update/main.svelte b/test/runtime/samples/await-conservative-update/main.svelte new file mode 100644 index 0000000000..91c9a6c4c2 --- /dev/null +++ b/test/runtime/samples/await-conservative-update/main.svelte @@ -0,0 +1,19 @@ + + +{#await get_promise()} +

loading...

+{:then value} +

the answer is {value}

+

count: {count}

+{/await} \ No newline at end of file diff --git a/test/runtime/samples/await-conservative-update/sleep.js b/test/runtime/samples/await-conservative-update/sleep.js new file mode 100644 index 0000000000..994f85f38a --- /dev/null +++ b/test/runtime/samples/await-conservative-update/sleep.js @@ -0,0 +1,11 @@ +export let stopped = false; + +export const stop = () => stopped = true; + +export const sleep = ms => new Promise(f => { + if (stopped) return; + setTimeout(() => { + if (stopped) return; + f(); + }, ms); +}); \ No newline at end of file