Skip to content

Better process effects #11560

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 5 commits into from
May 11, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 5 additions & 0 deletions .changeset/cyan-colts-raise.md
Original file line number Diff line number Diff line change
@@ -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
Original file line number Diff line number Diff line change
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) {
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Why is the if condition inside the for loop? It looks like it isn't dependent on the content so can be switched

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

What do you mean? Feel free to put up a PR to show what you mean. :)

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