fix: ensure child effects are removed from parent branches (#10985)

* fix: ensure child effects are removed from parent branches

* fix: child effects are removed from parent branches

* oops
pull/10983/head
Dominic Gannaway 9 months ago committed by GitHub
parent 5b2d5212d2
commit b119600966
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194

@ -0,0 +1,5 @@
---
"svelte": patch
---
fix: child effects are removed from parent branches

@ -70,19 +70,22 @@ export function derived_safe_equal(fn) {
* @returns {void}
*/
function destroy_derived_children(signal) {
var effects = signal.effects;
// TODO: should it be possible to create effects in deriveds given they're meant to be pure?
if (signal.effects) {
for (var i = 0; i < signal.effects.length; i += 1) {
destroy_effect(signal.effects[i]);
}
if (effects !== null) {
signal.effects = null;
for (var i = 0; i < effects.length; i += 1) {
destroy_effect(effects[i]);
}
}
var deriveds = signal.deriveds;
if (signal.deriveds) {
for (i = 0; i < signal.deriveds.length; i += 1) {
destroy_derived(signal.deriveds[i]);
}
if (deriveds !== null) {
signal.deriveds = null;
for (i = 0; i < deriveds.length; i += 1) {
destroy_derived(deriveds[i]);
}
}
}

@ -237,11 +237,22 @@ export function destroy_effect(effect) {
remove(effect.dom);
}
var parent = effect.parent;
if (parent !== null && (effect.f & BRANCH_EFFECT) !== 0) {
var effects = parent.effects;
if (effects !== null) {
var index = effects.indexOf(effect);
effects.splice(index, 1);
}
}
effect.effects =
effect.teardown =
effect.ctx =
effect.dom =
effect.deps =
effect.parent =
// @ts-expect-error
effect.fn =
null;

@ -353,11 +353,13 @@ export function remove_reactions(signal, start_index) {
* @returns {void}
*/
export function destroy_children(signal) {
if (signal.effects) {
for (var i = 0; i < signal.effects.length; i += 1) {
destroy_effect(signal.effects[i]);
}
var effects = signal.effects;
if (effects !== null) {
signal.effects = null;
for (var i = 0; i < effects.length; i += 1) {
destroy_effect(effects[i]);
}
}
}

Loading…
Cancel
Save