Skip to content

Commit 844e89f

Browse files
committed
correctly mount await block that has an anchor
1 parent 82fc0f2 commit 844e89f

File tree

3 files changed

+69
-1
lines changed

3 files changed

+69
-1
lines changed

src/generators/dom/visitors/AwaitBlock.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -110,7 +110,7 @@ export default function visitAwaitBlock(
110110
const anchorNode = state.parentNode ? 'null' : 'anchor';
111111

112112
block.builders.mount.addBlock(deindent`
113-
${await_block}.m(${targetNode}, ${anchor});
113+
${await_block}.m(${targetNode}, ${anchorNode});
114114
`);
115115

116116
const conditions = [];
Lines changed: 53 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,53 @@
1+
let fulfil;
2+
3+
let thePromise = new Promise(f => {
4+
fulfil = f;
5+
});
6+
7+
export default {
8+
data: {
9+
thePromise
10+
},
11+
12+
html: `
13+
<p>loading...</p>
14+
<p>loading...</p>
15+
`,
16+
17+
test(assert, component, target) {
18+
fulfil(42);
19+
20+
return thePromise
21+
.then(() => {
22+
assert.htmlEqual(target.innerHTML, `
23+
<p>the value is 42</p>
24+
<p>the value is 42</p>
25+
`);
26+
27+
let reject;
28+
29+
thePromise = new Promise((f, r) => {
30+
reject = r;
31+
});
32+
33+
component.set({
34+
thePromise
35+
});
36+
37+
assert.htmlEqual(target.innerHTML, `
38+
<p>loading...</p>
39+
<p>loading...</p>
40+
`);
41+
42+
reject(new Error('something broke'));
43+
44+
return thePromise.catch(() => {});
45+
})
46+
.then(() => {
47+
assert.htmlEqual(target.innerHTML, `
48+
<p>oh no! something broke</p>
49+
<p>oh no! something broke</p>
50+
`);
51+
});
52+
}
53+
};
Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
{{#await thePromise}}
2+
<p>loading...</p>
3+
{{then theValue}}
4+
<p>the value is {{theValue}}</p>
5+
{{catch theError}}
6+
<p>oh no! {{theError.message}}</p>
7+
{{/await}}
8+
9+
{{#await thePromise}}
10+
<p>loading...</p>
11+
{{then theValue}}
12+
<p>the value is {{theValue}}</p>
13+
{{catch theError}}
14+
<p>oh no! {{theError.message}}</p>
15+
{{/await}}

0 commit comments

Comments
 (0)