From a4e4bd0f53b0f716eb9d0b9f8e432c17737f3562 Mon Sep 17 00:00:00 2001 From: Jesse Skinner Date: Thu, 22 Oct 2020 12:43:11 -0400 Subject: [PATCH] get context at start of {#if} update block instead of at the end (#5531) --- .../compile/render_dom/wrappers/AwaitBlock.ts | 2 +- .../await-then-destruct-object-if/_config.js | 29 +++++++++++++++++++ .../await-then-destruct-object-if/main.svelte | 19 ++++++++++++ 3 files changed, 49 insertions(+), 1 deletion(-) create mode 100644 test/runtime/samples/await-then-destruct-object-if/_config.js create mode 100644 test/runtime/samples/await-then-destruct-object-if/main.svelte diff --git a/src/compiler/compile/render_dom/wrappers/AwaitBlock.ts b/src/compiler/compile/render_dom/wrappers/AwaitBlock.ts index 2bdc31948d..2038943d8b 100644 --- a/src/compiler/compile/render_dom/wrappers/AwaitBlock.ts +++ b/src/compiler/compile/render_dom/wrappers/AwaitBlock.ts @@ -96,7 +96,7 @@ class AwaitBlockBranch extends Wrapper { `); this.block.chunks.declarations.push(b`${get_context}(#ctx)`); if (this.block.has_update_method) { - this.block.chunks.update.push(b`${get_context}(#ctx)`); + this.block.chunks.update.unshift(b`${get_context}(#ctx)`); } } } diff --git a/test/runtime/samples/await-then-destruct-object-if/_config.js b/test/runtime/samples/await-then-destruct-object-if/_config.js new file mode 100644 index 0000000000..6a29b2db37 --- /dev/null +++ b/test/runtime/samples/await-then-destruct-object-if/_config.js @@ -0,0 +1,29 @@ +export default { + props: { + thePromise: Promise.resolve({ result: 1 }) + }, + + html: '', + + async test({ assert, component, target }) { + await (component.thePromise = Promise.resolve({ result: 1 })); + + assert.htmlEqual( + target.innerHTML, + ` +

result: 1

+

count: 0

+ ` + ); + + await new Promise(resolve => setTimeout(resolve, 1)); + + assert.htmlEqual( + target.innerHTML, + ` +

result: 1

+

count: 1

+ ` + ); + } +}; diff --git a/test/runtime/samples/await-then-destruct-object-if/main.svelte b/test/runtime/samples/await-then-destruct-object-if/main.svelte new file mode 100644 index 0000000000..3425979e2c --- /dev/null +++ b/test/runtime/samples/await-then-destruct-object-if/main.svelte @@ -0,0 +1,19 @@ + + +{#await thePromise then { result }} + {#if result} +

result: {result}

+

count: {count}

+ {:else} +

result: {result}

+

count: {count}

+ {/if} +{/await}