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 <rich.harris@vercel.com>

---------

Co-authored-by: Rich Harris <rich.harris@vercel.com>
pull/10955/head
Dominic Gannaway 2 years ago committed by GitHub
parent 9a4cd7e8d8
commit cb18f8fbbe
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194

@ -39,9 +39,10 @@ import { remove } from '../dom/reconciler.js';
* @returns {import('#client').Effect} * @returns {import('#client').Effect}
*/ */
function create_effect(type, fn, sync, init = true) { function create_effect(type, fn, sync, init = true) {
var is_root = (type & ROOT_EFFECT) !== 0;
/** @type {import('#client').Effect} */ /** @type {import('#client').Effect} */
const effect = { var effect = {
parent: current_effect, parent: is_root ? null : current_effect,
dom: null, dom: null,
deps: null, deps: null,
f: type | DIRTY, f: type | DIRTY,
@ -58,7 +59,7 @@ function create_effect(type, fn, sync, init = true) {
effect.l = current_effect.l + 1; effect.l = current_effect.l + 1;
} }
if (current_reaction !== null) { if (current_reaction !== null && !is_root) {
if (current_reaction.effects === null) { if (current_reaction.effects === null) {
current_reaction.effects = [effect]; current_reaction.effects = [effect];
} else { } else {
@ -68,7 +69,7 @@ function create_effect(type, fn, sync, init = true) {
if (init) { if (init) {
if (sync) { if (sync) {
const previously_flushing_effect = is_flushing_effect; var previously_flushing_effect = is_flushing_effect;
try { try {
set_is_flushing_effect(true); set_is_flushing_effect(true);

@ -360,12 +360,7 @@ export function remove_reactions(signal, start_index) {
export function destroy_children(signal) { export function destroy_children(signal) {
if (signal.effects) { if (signal.effects) {
for (var i = 0; i < signal.effects.length; i += 1) { for (var i = 0; i < signal.effects.length; i += 1) {
var effect = signal.effects[i]; destroy_effect(signal.effects[i]);
// TODO ideally root effects would be parentless
if ((effect.f & ROOT_EFFECT) === 0) {
destroy_effect(effect);
}
} }
signal.effects = null; signal.effects = null;
} }

Loading…
Cancel
Save