Skip to content

Commit a4e4bd0

Browse files
authored
get context at start of {#if} update block instead of at the end (#5531)
1 parent f038cf7 commit a4e4bd0

File tree

3 files changed

+49
-1
lines changed

3 files changed

+49
-1
lines changed

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -96,7 +96,7 @@ class AwaitBlockBranch extends Wrapper {
9696
`);
9797
this.block.chunks.declarations.push(b`${get_context}(#ctx)`);
9898
if (this.block.has_update_method) {
99-
this.block.chunks.update.push(b`${get_context}(#ctx)`);
99+
this.block.chunks.update.unshift(b`${get_context}(#ctx)`);
100100
}
101101
}
102102
}
Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,29 @@
1+
export default {
2+
props: {
3+
thePromise: Promise.resolve({ result: 1 })
4+
},
5+
6+
html: '',
7+
8+
async test({ assert, component, target }) {
9+
await (component.thePromise = Promise.resolve({ result: 1 }));
10+
11+
assert.htmlEqual(
12+
target.innerHTML,
13+
`
14+
<p>result: 1</p>
15+
<p>count: 0</p>
16+
`
17+
);
18+
19+
await new Promise(resolve => setTimeout(resolve, 1));
20+
21+
assert.htmlEqual(
22+
target.innerHTML,
23+
`
24+
<p>result: 1</p>
25+
<p>count: 1</p>
26+
`
27+
);
28+
}
29+
};
Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
<script>
2+
export let thePromise;
3+
4+
let count = 0;
5+
6+
setTimeout(() => {
7+
count++;
8+
}, 0);
9+
</script>
10+
11+
{#await thePromise then { result }}
12+
{#if result}
13+
<p>result: {result}</p>
14+
<p>count: {count}</p>
15+
{:else}
16+
<p>result: {result}</p>
17+
<p>count: {count}</p>
18+
{/if}
19+
{/await}

0 commit comments

Comments
 (0)