Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix reactive updates not reflected when handle promise #3663

Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 7 additions & 1 deletion src/runtime/internal/await_block.ts
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,8 @@ export function handle_promise(promise, info) {
const child_ctx = assign(assign({}, info.ctx), info.resolved);
const block = type && (info.current = type)(child_ctx);

let needs_flush = false;

if (info.block) {
if (info.blocks) {
info.blocks.forEach((block, i) => {
Expand All @@ -33,11 +35,15 @@ export function handle_promise(promise, info) {
transition_in(block, 1);
block.m(info.mount(), info.anchor);

flush();
needs_flush = true;
}

info.block = block;
if (info.blocks) info.blocks[index] = block;

if (needs_flush) {
flush();
}
}

if (is_promise(promise)) {
Expand Down
13 changes: 13 additions & 0 deletions test/runtime/samples/await-set-simultaneous-reactive/_config.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
export default {
html: `<p>wait for it...</p>`,
test({ assert, component, target }) {

return component.promise
.then(() => {
assert.htmlEqual(target.innerHTML, `
<p>the answer is 42!</p>
<p>the answer100 is 4200!</p>
`);
});
}
};
21 changes: 21 additions & 0 deletions test/runtime/samples/await-set-simultaneous-reactive/main.svelte
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
<script>
let answer = 0;
$: answer100 = answer * 100;
export let promise = new Promise(resolve => {
setTimeout(() => {
resolve();
answer = 42;
}, 0)
});
</script>

{#if promise}
{#await promise}
<p>wait for it...</p>
{:then _}
<p>the answer is {answer}!</p>
<p>the answer100 is {answer100}!</p>
{:catch error}
<p>well that's odd</p>
{/await}
{/if}