fix: flush anything pending before invoking flushSync callback function (#18878)

no new test here but it's necessary for #18861 to work, and we might as
well extract it
pull/18725/merge
Simon H 5 days ago committed by GitHub
parent da2f83343b
commit 98e547535d
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194

@ -0,0 +1,5 @@
---
'svelte': patch
---
fix: flush anything pending before invoking flushSync callback function

@ -1032,15 +1032,15 @@ export class Batch {
*/ */
export function flushSync(fn) { export function flushSync(fn) {
var was_flushing_sync = is_flushing_sync; var was_flushing_sync = is_flushing_sync;
var prev_previous_batch = previous_batch;
previous_batch = null;
is_flushing_sync = true; is_flushing_sync = true;
try { try {
var result; var result;
if (fn) { if (fn) {
if (current_batch !== null && !current_batch.is_fork) { flushSync(); // flush anything pending through the while loop below
current_batch.flush();
}
result = fn(); result = fn();
} }
@ -1056,6 +1056,7 @@ export function flushSync(fn) {
} }
} finally { } finally {
is_flushing_sync = was_flushing_sync; is_flushing_sync = was_flushing_sync;
previous_batch = prev_previous_batch;
} }
} }
@ -1406,6 +1407,8 @@ export function fork(fn) {
e.fork_timing(); e.fork_timing();
} }
flushSync();
var batch = Batch.ensure(); var batch = Batch.ensure();
batch.is_fork = true; batch.is_fork = true;
batch_values = new Map(); batch_values = new Map();
@ -1413,7 +1416,8 @@ export function fork(fn) {
var committed = false; var committed = false;
var settled = batch.settled(); var settled = batch.settled();
flushSync(fn); fn();
flushSync();
return { return {
commit: async () => { commit: async () => {

Loading…
Cancel
Save