diff --git a/src/generators/nodes/AwaitBlock.ts b/src/generators/nodes/AwaitBlock.ts index abc9d2c75a..3b928f7804 100644 --- a/src/generators/nodes/AwaitBlock.ts +++ b/src/generators/nodes/AwaitBlock.ts @@ -101,6 +101,10 @@ export default class AwaitBlock extends Node { block.addVariable(promise); block.addVariable(resolved); + // the `#component.root.set({})` below is just a cheap way to flush + // any oncreate handlers. We could have a dedicated `flush()` method + // but it's probably not worth it + block.builders.init.addBlock(deindent` function ${replace_await_block}(${token}, type, ${value}, ${params}) { if (${token} !== ${await_token}) return; @@ -113,6 +117,8 @@ export default class AwaitBlock extends Node { ${old_block}.d(); ${await_block}.c(); ${await_block}.m(${updateMountNode}, ${anchor}); + + #component.root.set({}); } } diff --git a/test/runtime/samples/await-component-oncreate/Foo.html b/test/runtime/samples/await-component-oncreate/Foo.html new file mode 100644 index 0000000000..61362eee09 --- /dev/null +++ b/test/runtime/samples/await-component-oncreate/Foo.html @@ -0,0 +1,14 @@ +

{{value}}

+

{{called}}

+ + \ No newline at end of file diff --git a/test/runtime/samples/await-component-oncreate/_config.js b/test/runtime/samples/await-component-oncreate/_config.js new file mode 100644 index 0000000000..417cbb8b14 --- /dev/null +++ b/test/runtime/samples/await-component-oncreate/_config.js @@ -0,0 +1,16 @@ +const promise = Promise.resolve(42); + +export default { + data: { + promise + }, + + test(assert, component, target) { + return promise.then(() => { + assert.htmlEqual(target.innerHTML, ` +

42

+

true

+ `); + }); + } +}; \ No newline at end of file diff --git a/test/runtime/samples/await-component-oncreate/main.html b/test/runtime/samples/await-component-oncreate/main.html new file mode 100644 index 0000000000..579f19f199 --- /dev/null +++ b/test/runtime/samples/await-component-oncreate/main.html @@ -0,0 +1,13 @@ +{{#await promise then value}} + +{{/await}} + + \ No newline at end of file