Skip to content

Commit 4947283

Browse files
authored
fix: avoid microtask in flushSync (#16394)
* fix: avoid microtask in flushSync * fix/simplify * on second thoughts * changeset
1 parent be44f8b commit 4947283

File tree

2 files changed

+16
-9
lines changed

2 files changed

+16
-9
lines changed

.changeset/soft-moles-work.md

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
---
2+
'svelte': patch
3+
---
4+
5+
fix: avoid microtask in flushSync

packages/svelte/src/internal/client/reactivity/batch.js

Lines changed: 11 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -416,19 +416,21 @@ export class Batch {
416416
return (this.#deferred ??= deferred()).promise;
417417
}
418418

419-
static ensure() {
419+
static ensure(autoflush = true) {
420420
if (current_batch === null) {
421421
const batch = (current_batch = new Batch());
422422
batches.add(current_batch);
423423

424-
queueMicrotask(() => {
425-
if (current_batch !== batch) {
426-
// a flushSync happened in the meantime
427-
return;
428-
}
424+
if (autoflush) {
425+
queueMicrotask(() => {
426+
if (current_batch !== batch) {
427+
// a flushSync happened in the meantime
428+
return;
429+
}
429430

430-
batch.flush();
431-
});
431+
batch.flush();
432+
});
433+
}
432434
}
433435

434436
return current_batch;
@@ -449,7 +451,7 @@ export function flushSync(fn) {
449451

450452
var result;
451453

452-
const batch = Batch.ensure();
454+
const batch = Batch.ensure(false);
453455

454456
if (fn) {
455457
batch.flush_effects();

0 commit comments

Comments
 (0)
pFad - Phonifier reborn

Pfad - The Proxy pFad of © 2024 Garber Painting. All rights reserved.

Note: This service is not intended for secure transactions such as banking, social media, email, or purchasing. Use at your own risk. We assume no liability whatsoever for broken pages.


Alternative Proxies:

Alternative Proxy

pFad Proxy

pFad v3 Proxy

pFad v4 Proxy