Skip to content

Commit 12160e0

Browse files
committed
WIP sync effect pending updates
1 parent 9f59122 commit 12160e0

File tree

2 files changed

+18
-6
lines changed

2 files changed

+18
-6
lines changed

packages/svelte/src/internal/client/dom/blocks/boundary.js

Lines changed: 9 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -22,10 +22,11 @@ import { get_next_sibling } from '../operations.js';
2222
import { queue_micro_task } from '../task.js';
2323
import * as e from '../../errors.js';
2424
import { DEV } from 'esm-env';
25-
import { Batch } from '../../reactivity/batch.js';
25+
import { Batch, effect_pending_updates } from '../../reactivity/batch.js';
2626
import { internal_set, source } from '../../reactivity/sources.js';
2727
import { tag } from '../../dev/tracing.js';
2828
import { createSubscriber } from '../../../../reactivity/create-subscriber.js';
29+
import { raf } from '../../timing.js';
2930

3031
/**
3132
* @typedef {{
@@ -92,6 +93,12 @@ export class Boundary {
9293
*/
9394
#effect_pending = null;
9495

96+
#effect_pending_update = () => {
97+
if (this.#effect_pending) {
98+
internal_set(this.#effect_pending, this.#pending_count);
99+
}
100+
};
101+
95102
#effect_pending_subscriber = createSubscriber(() => {
96103
this.#effect_pending = source(this.#pending_count);
97104

@@ -238,11 +245,7 @@ export class Boundary {
238245
this.parent.#update_pending_count(d);
239246
}
240247

241-
queueMicrotask(() => {
242-
if (this.#effect_pending) {
243-
internal_set(this.#effect_pending, this.#pending_count);
244-
}
245-
});
248+
effect_pending_updates.add(this.#effect_pending_update);
246249
}
247250

248251
get_effect_pending() {

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

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -49,6 +49,9 @@ export let batch_deriveds = null;
4949
/** @type {Effect[]} Stack of effects, dev only */
5050
export let dev_effect_stack = [];
5151

52+
/** @type {Set<() => void>} */
53+
export let effect_pending_updates = new Set();
54+
5255
/** @type {Effect[]} */
5356
let queued_root_effects = [];
5457

@@ -320,6 +323,12 @@ export class Batch {
320323
}
321324

322325
current_batch = null;
326+
327+
for (const update of effect_pending_updates) {
328+
effect_pending_updates.delete(update);
329+
update();
330+
break;
331+
}
323332
}
324333

325334
flush_effects() {

0 commit comments

Comments
 (0)