Skip to content

Commit

Permalink
get context at start of {#if} update block instead of at the end (#5531)
Browse files Browse the repository at this point in the history
  • Loading branch information
jesseskinner authored Oct 22, 2020
1 parent f038cf7 commit a4e4bd0
Show file tree
Hide file tree
Showing 3 changed files with 49 additions and 1 deletion.
2 changes: 1 addition & 1 deletion src/compiler/compile/render_dom/wrappers/AwaitBlock.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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)`);
}
}
}
Expand Down
29 changes: 29 additions & 0 deletions test/runtime/samples/await-then-destruct-object-if/_config.js
Original file line number Diff line number Diff line change
@@ -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,
`
<p>result: 1</p>
<p>count: 0</p>
`
);

await new Promise(resolve => setTimeout(resolve, 1));

assert.htmlEqual(
target.innerHTML,
`
<p>result: 1</p>
<p>count: 1</p>
`
);
}
};
19 changes: 19 additions & 0 deletions test/runtime/samples/await-then-destruct-object-if/main.svelte
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
<script>
export let thePromise;
let count = 0;
setTimeout(() => {
count++;
}, 0);
</script>

{#await thePromise then { result }}
{#if result}
<p>result: {result}</p>
<p>count: {count}</p>
{:else}
<p>result: {result}</p>
<p>count: {count}</p>
{/if}
{/await}

0 comments on commit a4e4bd0

Please sign in to comment.