Skip to content

Commit

Permalink
Better process effects (#11560)
Browse files Browse the repository at this point in the history
* fix: improve internal mechanism for handling process_effects
  • Loading branch information
trueadm committed May 11, 2024
1 parent 4cadd07 commit 643bbf2
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 8 deletions.
5 changes: 5 additions & 0 deletions .changeset/cyan-colts-raise.md
@@ -0,0 +1,5 @@
---
"svelte": patch
---

fix: improve internal mechanism for handling process_effects
16 changes: 8 additions & 8 deletions packages/svelte/src/internal/client/runtime.js
Expand Up @@ -653,12 +653,13 @@ function process_effects(effect, filter_flags, shallow, collected_effects) {
}

if (effects.length > 0) {
if ((filter_flags & EFFECT) !== 0) {
collected_effects.push(...effects);
}

if (!shallow) {
for (var i = 0; i < effects.length; i++) {
// We might be dealing with many effects here, far more than can be spread into
// an array push call (callstack overflow). So let's deal with each effect in a loop.
for (var i = 0; i < effects.length; i++) {
if ((filter_flags & EFFECT) !== 0) {
collected_effects.push(effects[i]);
}
if (!shallow) {
process_effects(effects[i], filter_flags, false, collected_effects);
}
}
Expand All @@ -677,7 +678,6 @@ function process_effects(effect, filter_flags, shallow, collected_effects) {
* @returns {void}
*/
function flush_nested_effects(effect, filter_flags, shallow = false) {
infinite_loop_guard();
/** @type {import('#client').Effect[]} */
var collected_effects = [];

Expand Down Expand Up @@ -1163,7 +1163,7 @@ export function pop(component) {
const effects = context_stack_item.e;
if (effects !== null) {
context_stack_item.e = null;
for (let i = 0; i < effects.length; i++) {
for (var i = 0; i < effects.length; i++) {
effect(effects[i]);
}
}
Expand Down

0 comments on commit 643bbf2

Please sign in to comment.