Skip to content

Commit 4b04b16

Browse files
authored
avoid using .shift() in flush() (#4356)
1 parent a40f4ad commit 4b04b16

File tree

1 file changed

+8
-2
lines changed

1 file changed

+8
-2
lines changed

src/runtime/internal/scheduler.ts

+8-2
Original file line numberDiff line numberDiff line change
@@ -31,18 +31,23 @@ export function add_flush_callback(fn) {
3131
flush_callbacks.push(fn);
3232
}
3333

34+
let flushing = false;
3435
const seen_callbacks = new Set();
3536
export function flush() {
37+
if (flushing) return;
38+
flushing = true;
3639

3740
do {
3841
// first, call beforeUpdate functions
3942
// and update components
40-
while (dirty_components.length) {
41-
const component = dirty_components.shift();
43+
for (let i = 0; i < dirty_components.length; i += 1) {
44+
const component = dirty_components[i];
4245
set_current_component(component);
4346
update(component.$$);
4447
}
4548

49+
dirty_components.length = 0;
50+
4651
while (binding_callbacks.length) binding_callbacks.pop()();
4752

4853
// then, once components are updated, call
@@ -67,6 +72,7 @@ export function flush() {
6772
}
6873

6974
update_scheduled = false;
75+
flushing = false;
7076
seen_callbacks.clear();
7177
}
7278

0 commit comments

Comments
 (0)