Skip to content

Commit 643bbf2

Browse files
authored
Better process effects (#11560)
* fix: improve internal mechanism for handling process_effects
1 parent 4cadd07 commit 643bbf2

File tree

2 files changed

+13
-8
lines changed

2 files changed

+13
-8
lines changed

.changeset/cyan-colts-raise.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: improve internal mechanism for handling process_effects

packages/svelte/src/internal/client/runtime.js

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -653,12 +653,13 @@ function process_effects(effect, filter_flags, shallow, collected_effects) {
653653
}
654654

655655
if (effects.length > 0) {
656-
if ((filter_flags & EFFECT) !== 0) {
657-
collected_effects.push(...effects);
658-
}
659-
660-
if (!shallow) {
661-
for (var i = 0; i < effects.length; i++) {
656+
// We might be dealing with many effects here, far more than can be spread into
657+
// an array push call (callstack overflow). So let's deal with each effect in a loop.
658+
for (var i = 0; i < effects.length; i++) {
659+
if ((filter_flags & EFFECT) !== 0) {
660+
collected_effects.push(effects[i]);
661+
}
662+
if (!shallow) {
662663
process_effects(effects[i], filter_flags, false, collected_effects);
663664
}
664665
}
@@ -677,7 +678,6 @@ function process_effects(effect, filter_flags, shallow, collected_effects) {
677678
* @returns {void}
678679
*/
679680
function flush_nested_effects(effect, filter_flags, shallow = false) {
680-
infinite_loop_guard();
681681
/** @type {import('#client').Effect[]} */
682682
var collected_effects = [];
683683

@@ -1163,7 +1163,7 @@ export function pop(component) {
11631163
const effects = context_stack_item.e;
11641164
if (effects !== null) {
11651165
context_stack_item.e = null;
1166-
for (let i = 0; i < effects.length; i++) {
1166+
for (var i = 0; i < effects.length; i++) {
11671167
effect(effects[i]);
11681168
}
11691169
}

0 commit comments

Comments
 (0)