Skip to content

Commit f667787

Browse files
Update packages/svelte/src/internal/client/reactivity/batch.js
Co-authored-by: Simon H <[email protected]>
1 parent 2e5c15f commit f667787

File tree

1 file changed

+11
-9
lines changed
  • packages/svelte/src/internal/client/reactivity

1 file changed

+11
-9
lines changed

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

Lines changed: 11 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -703,18 +703,18 @@ export function schedule_effect(signal) {
703703
queued_root_effects.push(effect);
704704
}
705705

706-
/** @type {Source<number>} */
707-
let version;
708-
709-
let eager_flushing = false;
706+
/** @type {Source<number>[] | null} */
707+
let eager_flushing = null;
710708

711709
function eager_flush() {
712710
try {
713711
flushSync(() => {
714-
update(version);
712+
/** @type {Source<number>[]} */ (eager_flushing).forEach((version) => {
713+
update(version);
714+
});
715715
});
716716
} finally {
717-
eager_flushing = false;
717+
eager_flushing = null;
718718
}
719719
}
720720

@@ -725,11 +725,12 @@ function eager_flush() {
725725
* @returns {T}
726726
*/
727727
export function eager(fn) {
728-
get((version ??= source(0)));
729-
728+
var version = source(0);
730729
var initial = true;
731730
var value = /** @type {T} */ (undefined);
732731

732+
get(version);
733+
733734
inspect_effect(() => {
734735
if (initial) {
735736
// the first time this runs, we create an inspect effect
@@ -750,9 +751,10 @@ export function eager(fn) {
750751
// `version` update. since this will recreate the effect,
751752
// we don't need to evaluate the expression here
752753
if (!eager_flushing) {
753-
eager_flushing = true;
754+
eager_flushing = [];
754755
queue_micro_task(eager_flush);
755756
}
757+
eager_flushing.push(version);
756758
});
757759

758760
initial = false;

0 commit comments

Comments
 (0)