Skip to content

Commit 29a1569

Browse files
authored
Merge pull request #1150 from sveltejs/gh-1131
prevent await blocks using stale state
2 parents 37d5260 + bf25248 commit 29a1569

File tree

3 files changed

+27
-0
lines changed

3 files changed

+27
-0
lines changed

src/generators/nodes/AwaitBlock.ts

+2
Original file line numberDiff line numberDiff line change
@@ -127,8 +127,10 @@ export default class AwaitBlock extends Node {
127127
128128
if (@isPromise(${promise})) {
129129
${promise}.then(function(${value}) {
130+
var state = #component.get();
130131
${replace_await_block}(${token}, ${create_then_block}, ${value}, ${params});
131132
}, function (${error}) {
133+
var state = #component.get();
132134
${replace_await_block}(${token}, ${create_catch_block}, ${error}, ${params});
133135
});
134136
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
export default {
2+
test(assert, component, target) {
3+
const promise = Promise.resolve().then(() => component.set({ answer: 42 }));
4+
5+
component.set({ promise });
6+
7+
assert.htmlEqual(target.innerHTML, `<p>wait for it...</p>`);
8+
9+
return promise
10+
.then(() => {
11+
assert.htmlEqual(target.innerHTML, `
12+
<p>the answer is 42!</p>
13+
`);
14+
});
15+
}
16+
};
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
{{#if promise}}
2+
{{#await promise}}
3+
<p>wait for it...</p>
4+
{{then _}}
5+
<p>the answer is {{answer}}!</p>
6+
{{catch error}}
7+
<p>well that's odd</p>
8+
{{/await}}
9+
{{/if}}

0 commit comments

Comments
 (0)