mirror of https://github.com/sveltejs/svelte
fix: group sync statements (#17977)
We were just putting each statement into its own promise. Besides this being bad for perf, it also introduces subtle timing issues - the execution order of the code could change in bad ways. Fixes #17940pull/17965/head
parent
425fba33fe
commit
6b33dd2a1e
@ -0,0 +1,5 @@
|
|||||||
|
---
|
||||||
|
'svelte': patch
|
||||||
|
---
|
||||||
|
|
||||||
|
fix: group sync statements
|
||||||
@ -0,0 +1,3 @@
|
|||||||
|
import { test } from '../../test';
|
||||||
|
|
||||||
|
export default test({ compileOptions: { experimental: { async: true } } });
|
||||||
@ -0,0 +1,26 @@
|
|||||||
|
import 'svelte/internal/disclose-version';
|
||||||
|
import 'svelte/internal/flags/async';
|
||||||
|
import * as $ from 'svelte/internal/client';
|
||||||
|
|
||||||
|
export default function Async_top_level_group_sync_run($$anchor) {
|
||||||
|
var a,
|
||||||
|
// these should be grouped into one, having an async tick inbetween
|
||||||
|
// would change how the code runs and could introduce subtle timing bugs
|
||||||
|
b,
|
||||||
|
c;
|
||||||
|
|
||||||
|
var $$promises = $.run([
|
||||||
|
async () => a = await Promise.resolve(1),
|
||||||
|
() => {
|
||||||
|
b = a + 1;
|
||||||
|
c = b + 1;
|
||||||
|
}
|
||||||
|
]);
|
||||||
|
|
||||||
|
$.next();
|
||||||
|
|
||||||
|
var text = $.text();
|
||||||
|
|
||||||
|
$.template_effect(() => $.set_text(text, c), void 0, void 0, [$$promises[1]]);
|
||||||
|
$.append($$anchor, text);
|
||||||
|
}
|
||||||
@ -0,0 +1,21 @@
|
|||||||
|
import 'svelte/internal/flags/async';
|
||||||
|
import * as $ from 'svelte/internal/server';
|
||||||
|
|
||||||
|
export default function Async_top_level_group_sync_run($$renderer) {
|
||||||
|
var a,
|
||||||
|
// these should be grouped into one, having an async tick inbetween
|
||||||
|
// would change how the code runs and could introduce subtle timing bugs
|
||||||
|
b,
|
||||||
|
c;
|
||||||
|
|
||||||
|
var $$promises = $$renderer.run([
|
||||||
|
async () => a = await Promise.resolve(1),
|
||||||
|
() => {
|
||||||
|
b = a + 1;
|
||||||
|
c = b + 1;
|
||||||
|
}
|
||||||
|
]);
|
||||||
|
|
||||||
|
$$renderer.push(`<!---->`);
|
||||||
|
$$renderer.async([$$promises[1]], ($$renderer) => $$renderer.push(() => $.escape(c)));
|
||||||
|
}
|
||||||
@ -0,0 +1,9 @@
|
|||||||
|
<script>
|
||||||
|
let a = await Promise.resolve(1);
|
||||||
|
// these should be grouped into one, having an async tick inbetween
|
||||||
|
// would change how the code runs and could introduce subtle timing bugs
|
||||||
|
let b = a + 1;
|
||||||
|
let c = b + 1;
|
||||||
|
</script>
|
||||||
|
|
||||||
|
{c}
|
||||||
Loading…
Reference in new issue