diff --git a/packages/solid/src/reactive/signal.ts b/packages/solid/src/reactive/signal.ts index 24929d0a0..dca1128ad 100644 --- a/packages/solid/src/reactive/signal.ts +++ b/packages/solid/src/reactive/signal.ts @@ -90,6 +90,7 @@ export interface Owner { context: any | null; sourceMap?: SourceMapValue[]; name?: string; + isCleaning?: boolean; } export interface Computation extends Owner { @@ -1634,43 +1635,51 @@ function markDownstream(node: Memo) { } function cleanNode(node: Owner) { - let i; - if ((node as Computation).sources) { - while ((node as Computation).sources!.length) { - const source = (node as Computation).sources!.pop()!, - index = (node as Computation).sourceSlots!.pop()!, - obs = source.observers; - if (obs && obs.length) { - const n = obs.pop()!, - s = source.observerSlots!.pop()!; - if (index < obs.length) { - n.sourceSlots![s] = index; - obs[index] = n; - source.observerSlots![index] = s; + if (node.isCleaning === true) { + return; + } + node.isCleaning = true; + try { + let i; + if ((node as Computation).sources) { + while ((node as Computation).sources!.length) { + const source = (node as Computation).sources!.pop()!, + index = (node as Computation).sourceSlots!.pop()!, + obs = source.observers; + if (obs && obs.length) { + const n = obs.pop()!, + s = source.observerSlots!.pop()!; + if (index < obs.length) { + n.sourceSlots![s] = index; + obs[index] = n; + source.observerSlots![index] = s; + } } } } - } - if (Transition && Transition.running && (node as Memo).pure) { - if ((node as Memo).tOwned) { - for (i = (node as Memo).tOwned!.length - 1; i >= 0; i--) - cleanNode((node as Memo).tOwned![i]); - delete (node as Memo).tOwned; + if (Transition && Transition.running && (node as Memo).pure) { + if ((node as Memo).tOwned) { + for (i = (node as Memo).tOwned!.length - 1; i >= 0; i--) + cleanNode((node as Memo).tOwned![i]); + delete (node as Memo).tOwned; + } + reset(node as Computation, true); + } else if (node.owned) { + for (i = node.owned.length - 1; i >= 0; i--) cleanNode(node.owned[i]); + node.owned = null; } - reset(node as Computation, true); - } else if (node.owned) { - for (i = node.owned.length - 1; i >= 0; i--) cleanNode(node.owned[i]); - node.owned = null; - } - if (node.cleanups) { - for (i = node.cleanups.length - 1; i >= 0; i--) node.cleanups[i](); - node.cleanups = null; + if (node.cleanups) { + for (i = node.cleanups.length - 1; i >= 0; i--) node.cleanups[i](); + node.cleanups = null; + } + if (Transition && Transition.running) (node as Computation).tState = 0; + else (node as Computation).state = 0; + "_SOLID_DEV_" && delete node.sourceMap; + } finally { + node.isCleaning = false; } - if (Transition && Transition.running) (node as Computation).tState = 0; - else (node as Computation).state = 0; - "_SOLID_DEV_" && delete node.sourceMap; } function reset(node: Computation, top?: boolean) {