Skip to content

Commit 4cff3e4

Browse files
committed
lock on the cleanNode function
1 parent c71b6fe commit 4cff3e4

1 file changed

Lines changed: 39 additions & 30 deletions

File tree

packages/solid/src/reactive/signal.ts

Lines changed: 39 additions & 30 deletions
Original file line numberDiff line numberDiff line change
@@ -90,6 +90,7 @@ export interface Owner {
9090
context: any | null;
9191
sourceMap?: SourceMapValue[];
9292
name?: string;
93+
isCleaning?: boolean;
9394
}
9495

9596
export interface Computation<Init, Next extends Init = Init> extends Owner {
@@ -1634,43 +1635,51 @@ function markDownstream(node: Memo<any>) {
16341635
}
16351636

16361637
function cleanNode(node: Owner) {
1637-
let i;
1638-
if ((node as Computation<any>).sources) {
1639-
while ((node as Computation<any>).sources!.length) {
1640-
const source = (node as Computation<any>).sources!.pop()!,
1641-
index = (node as Computation<any>).sourceSlots!.pop()!,
1642-
obs = source.observers;
1643-
if (obs && obs.length) {
1644-
const n = obs.pop()!,
1645-
s = source.observerSlots!.pop()!;
1646-
if (index < obs.length) {
1647-
n.sourceSlots![s] = index;
1648-
obs[index] = n;
1649-
source.observerSlots![index] = s;
1638+
if (node.isCleaning === true) {
1639+
return;
1640+
}
1641+
node.isCleaning = true;
1642+
try {
1643+
let i;
1644+
if ((node as Computation<any>).sources) {
1645+
while ((node as Computation<any>).sources!.length) {
1646+
const source = (node as Computation<any>).sources!.pop()!,
1647+
index = (node as Computation<any>).sourceSlots!.pop()!,
1648+
obs = source.observers;
1649+
if (obs && obs.length) {
1650+
const n = obs.pop()!,
1651+
s = source.observerSlots!.pop()!;
1652+
if (index < obs.length) {
1653+
n.sourceSlots![s] = index;
1654+
obs[index] = n;
1655+
source.observerSlots![index] = s;
1656+
}
16501657
}
16511658
}
16521659
}
1653-
}
16541660

1655-
if (Transition && Transition.running && (node as Memo<any>).pure) {
1656-
if ((node as Memo<any>).tOwned) {
1657-
for (i = (node as Memo<any>).tOwned!.length - 1; i >= 0; i--)
1658-
cleanNode((node as Memo<any>).tOwned![i]);
1659-
delete (node as Memo<any>).tOwned;
1661+
if (Transition && Transition.running && (node as Memo<any>).pure) {
1662+
if ((node as Memo<any>).tOwned) {
1663+
for (i = (node as Memo<any>).tOwned!.length - 1; i >= 0; i--)
1664+
cleanNode((node as Memo<any>).tOwned![i]);
1665+
delete (node as Memo<any>).tOwned;
1666+
}
1667+
reset(node as Computation<any>, true);
1668+
} else if (node.owned) {
1669+
for (i = node.owned.length - 1; i >= 0; i--) cleanNode(node.owned[i]);
1670+
node.owned = null;
16601671
}
1661-
reset(node as Computation<any>, true);
1662-
} else if (node.owned) {
1663-
for (i = node.owned.length - 1; i >= 0; i--) cleanNode(node.owned[i]);
1664-
node.owned = null;
1665-
}
16661672

1667-
if (node.cleanups) {
1668-
for (i = node.cleanups.length - 1; i >= 0; i--) node.cleanups[i]();
1669-
node.cleanups = null;
1673+
if (node.cleanups) {
1674+
for (i = node.cleanups.length - 1; i >= 0; i--) node.cleanups[i]();
1675+
node.cleanups = null;
1676+
}
1677+
if (Transition && Transition.running) (node as Computation<any>).tState = 0;
1678+
else (node as Computation<any>).state = 0;
1679+
"_SOLID_DEV_" && delete node.sourceMap;
1680+
} finally {
1681+
node.isCleaning = false;
16701682
}
1671-
if (Transition && Transition.running) (node as Computation<any>).tState = 0;
1672-
else (node as Computation<any>).state = 0;
1673-
"_SOLID_DEV_" && delete node.sourceMap;
16741683
}
16751684

16761685
function reset(node: Computation<any>, top?: boolean) {

0 commit comments

Comments
 (0)