Skip to content

Commit 7f1e162

Browse files
committed
don't use stale itemCleanupPairRef
1 parent 224564e commit 7f1e162

File tree

2 files changed

+6
-8
lines changed

2 files changed

+6
-8
lines changed

libs/isograph-react-disposable-state/src/useDisposableState.ts

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -54,11 +54,11 @@ export function useDisposableState<T = never>(
5454
return;
5555
}
5656
lastCommittedParentCache.current = parentCache;
57-
// capture last set pair in a variable
58-
const current = itemCleanupPairRef.current;
57+
5958
return () => {
60-
// current is a stale variable
61-
current?.[1]();
59+
if (itemCleanupPairRef.current !== null) {
60+
itemCleanupPairRef.current[1]();
61+
}
6262
};
6363
},
6464
[parentCache],

libs/isograph-react-disposable-state/src/useLazyDisposableState.ts

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -36,11 +36,9 @@ export function useLazyDisposableState<T>(
3636
return;
3737
}
3838
lastCommittedParentCache.current = parentCache;
39-
// capture last set pair in a variable
40-
const current = itemCleanupPairRef.current;
39+
4140
return () => {
42-
// current is a stale variable
43-
const cleanupFn = current?.[1];
41+
const cleanupFn = itemCleanupPairRef.current?.[1];
4442
// TODO confirm useEffect is called in order.
4543
if (cleanupFn == null) {
4644
throw new Error(

0 commit comments

Comments
 (0)