From cb18f8fbbe49c31db643b064ddfbcc4ef37fee08 Mon Sep 17 00:00:00 2001 From: Dominic Gannaway Date: Tue, 26 Mar 2024 22:09:01 +0000 Subject: [PATCH] chore: root effects should not have parents (#10950) * chore: root effects should not have parents * tune * oops * Update packages/svelte/src/internal/client/runtime.js Co-authored-by: Rich Harris --------- Co-authored-by: Rich Harris --- .../svelte/src/internal/client/reactivity/effects.js | 9 +++++---- packages/svelte/src/internal/client/runtime.js | 7 +------ 2 files changed, 6 insertions(+), 10 deletions(-) diff --git a/packages/svelte/src/internal/client/reactivity/effects.js b/packages/svelte/src/internal/client/reactivity/effects.js index 2f1fd291c9..7a9259698e 100644 --- a/packages/svelte/src/internal/client/reactivity/effects.js +++ b/packages/svelte/src/internal/client/reactivity/effects.js @@ -39,9 +39,10 @@ import { remove } from '../dom/reconciler.js'; * @returns {import('#client').Effect} */ function create_effect(type, fn, sync, init = true) { + var is_root = (type & ROOT_EFFECT) !== 0; /** @type {import('#client').Effect} */ - const effect = { - parent: current_effect, + var effect = { + parent: is_root ? null : current_effect, dom: null, deps: null, f: type | DIRTY, @@ -58,7 +59,7 @@ function create_effect(type, fn, sync, init = true) { effect.l = current_effect.l + 1; } - if (current_reaction !== null) { + if (current_reaction !== null && !is_root) { if (current_reaction.effects === null) { current_reaction.effects = [effect]; } else { @@ -68,7 +69,7 @@ function create_effect(type, fn, sync, init = true) { if (init) { if (sync) { - const previously_flushing_effect = is_flushing_effect; + var previously_flushing_effect = is_flushing_effect; try { set_is_flushing_effect(true); diff --git a/packages/svelte/src/internal/client/runtime.js b/packages/svelte/src/internal/client/runtime.js index bf80aa2cfe..e600295d6f 100644 --- a/packages/svelte/src/internal/client/runtime.js +++ b/packages/svelte/src/internal/client/runtime.js @@ -360,12 +360,7 @@ export function remove_reactions(signal, start_index) { export function destroy_children(signal) { if (signal.effects) { for (var i = 0; i < signal.effects.length; i += 1) { - var effect = signal.effects[i]; - - // TODO ideally root effects would be parentless - if ((effect.f & ROOT_EFFECT) === 0) { - destroy_effect(effect); - } + destroy_effect(signal.effects[i]); } signal.effects = null; }