diff --git a/src/compiler/compile/render_dom/wrappers/AwaitBlock.ts b/src/compiler/compile/render_dom/wrappers/AwaitBlock.ts
index ceb898bf7901..495f1b31575d 100644
--- a/src/compiler/compile/render_dom/wrappers/AwaitBlock.ts
+++ b/src/compiler/compile/render_dom/wrappers/AwaitBlock.ts
@@ -231,6 +231,15 @@ export default class AwaitBlockWrapper extends Wrapper {
const dependencies = this.node.expression.dynamic_dependencies();
+ let update_child_context;
+ if (this.then.value && this.catch.value) {
+ update_child_context = b`#child_ctx[${this.then.value_index}] = #child_ctx[${this.catch.value_index}] = ${info}.resolved;`;
+ } else if (this.then.value) {
+ update_child_context = b`#child_ctx[${this.then.value_index}] = ${info}.resolved;`;
+ } else if (this.catch.value) {
+ update_child_context = b`#child_ctx[${this.catch.value_index}] = ${info}.resolved;`;
+ }
+
if (dependencies.length > 0) {
const condition = x`
${block.renderer.dirty(dependencies)} &&
@@ -247,7 +256,7 @@ export default class AwaitBlockWrapper extends Wrapper {
} else {
const #child_ctx = #ctx.slice();
- ${this.then.value && b`#child_ctx[${this.then.value_index}] = ${info}.resolved;`}
+ ${update_child_context}
${info}.block.p(#child_ctx, #dirty);
}
`);
@@ -261,7 +270,7 @@ export default class AwaitBlockWrapper extends Wrapper {
block.chunks.update.push(b`
{
const #child_ctx = #ctx.slice();
- ${this.then.value && b`#child_ctx[${this.then.value_index}] = ${info}.resolved;`}
+ ${update_child_context}
${info}.block.p(#child_ctx, #dirty);
}
`);
diff --git a/test/runtime/samples/await-with-update-2/Component.svelte b/test/runtime/samples/await-with-update-2/Component.svelte
new file mode 100644
index 000000000000..1301db3f9908
--- /dev/null
+++ b/test/runtime/samples/await-with-update-2/Component.svelte
@@ -0,0 +1,7 @@
+
+
+
count: {count}
+value: {value}
\ No newline at end of file
diff --git a/test/runtime/samples/await-with-update-2/_config.js b/test/runtime/samples/await-with-update-2/_config.js
new file mode 100644
index 000000000000..d6e9b3e404fe
--- /dev/null
+++ b/test/runtime/samples/await-with-update-2/_config.js
@@ -0,0 +1,64 @@
+export default {
+ props: {
+ thePromise: new Promise((_) => {}),
+ count: 0,
+ },
+
+ html: `
+
+ `,
+
+ async test({ assert, component, target }) {
+ await (component.thePromise = Promise.resolve({ value: "success", Component: component.Component }));
+
+ assert.htmlEqual(
+ target.innerHTML,
+ `
+ Resolved:
+
count: 0
+
value: success
+
+ `
+ );
+
+ component.count = 5;
+
+ assert.htmlEqual(
+ target.innerHTML,
+ `
+ Resolved:
+
count: 5
+
value: success
+
+ `
+ );
+
+ try {
+ await (component.thePromise = Promise.reject({ value: "failure", Component: component.Component }));
+ } catch {
+ // ignore
+ }
+
+ assert.htmlEqual(
+ target.innerHTML,
+ `
+ Rejected:
+
count: 5
+
value: failure
+
+ `
+ );
+
+ component.count = 10;
+
+ assert.htmlEqual(
+ target.innerHTML,
+ `
+ Rejected:
+
count: 10
+
value: failure
+
+ `
+ );
+ },
+};
diff --git a/test/runtime/samples/await-with-update-2/main.svelte b/test/runtime/samples/await-with-update-2/main.svelte
new file mode 100644
index 000000000000..b29c875f920e
--- /dev/null
+++ b/test/runtime/samples/await-with-update-2/main.svelte
@@ -0,0 +1,16 @@
+
+
+
+ {#await thePromise}
+
loading...
+ {:then { value: theValue, Component }}
+ Resolved:
+ {:catch { value: theError, Component } }
+ Rejected:
+ {/await}
+
\ No newline at end of file
diff --git a/test/runtime/samples/await-with-update/Component.svelte b/test/runtime/samples/await-with-update/Component.svelte
new file mode 100644
index 000000000000..5f13c80e65f1
--- /dev/null
+++ b/test/runtime/samples/await-with-update/Component.svelte
@@ -0,0 +1,5 @@
+
+
+count: {count}
\ No newline at end of file
diff --git a/test/runtime/samples/await-with-update/_config.js b/test/runtime/samples/await-with-update/_config.js
new file mode 100644
index 000000000000..06e68c6eee52
--- /dev/null
+++ b/test/runtime/samples/await-with-update/_config.js
@@ -0,0 +1,60 @@
+export default {
+ props: {
+ thePromise: new Promise((_) => {}),
+ count: 0,
+ },
+
+ html: `
+
+ `,
+
+ async test({ assert, component, target }) {
+ await (component.thePromise = Promise.resolve(component.Component));
+
+ assert.htmlEqual(
+ target.innerHTML,
+ `
+
+ `
+ );
+
+ component.count = 5;
+
+ assert.htmlEqual(
+ target.innerHTML,
+ `
+
+ `
+ );
+
+ try {
+ await (component.thePromise = Promise.reject(component.Component));
+ } catch {
+ // ignore
+ }
+
+ assert.htmlEqual(
+ target.innerHTML,
+ `
+
+ `
+ );
+
+ component.count = 10;
+
+ assert.htmlEqual(
+ target.innerHTML,
+ `
+
+ `
+ );
+ },
+};
diff --git a/test/runtime/samples/await-with-update/main.svelte b/test/runtime/samples/await-with-update/main.svelte
new file mode 100644
index 000000000000..51c5b76a212e
--- /dev/null
+++ b/test/runtime/samples/await-with-update/main.svelte
@@ -0,0 +1,16 @@
+
+
+
+ {#await thePromise}
+
loading...
+ {:then theValue}
+ Resolved:
+ {:catch theError}
+ Rejected:
+ {/await}
+
\ No newline at end of file