diff --git a/src/useObserver.ts b/src/useObserver.ts index ad3609b..2ff48b8 100644 --- a/src/useObserver.ts +++ b/src/useObserver.ts @@ -15,7 +15,7 @@ function observerComponentNameFor(baseComponentName: string) { } /** - * We use class to make it easier to detect in heap explorer + * We use class to make it easier to detect in heap snapshots by name */ class ObjectToBeRetainedByReact {} diff --git a/src/utils/createReactionCleanupTrackingUsingFinalizationRegister.ts b/src/utils/createReactionCleanupTrackingUsingFinalizationRegister.ts index f5fc352..44f2038 100644 --- a/src/utils/createReactionCleanupTrackingUsingFinalizationRegister.ts +++ b/src/utils/createReactionCleanupTrackingUsingFinalizationRegister.ts @@ -35,15 +35,16 @@ export function createReactionCleanupTrackingUsingFinalizationRegister( reactionTrackingRef.current = createTrackingData(reaction) reactionTrackingRef.current.finalizationRegistryCleanupToken = token cleanupTokenToReactionTrackingMap.set(token, reactionTrackingRef.current) + return reactionTrackingRef.current }, recordReactionAsCommitted(reactionRef: React.MutableRefObject) { registry.unregister(reactionRef) - for (const [key, value] of cleanupTokenToReactionTrackingMap.entries()) { - if (value === reactionRef.current) { - cleanupTokenToReactionTrackingMap.delete(key) - } + if (reactionRef.current && reactionRef.current.finalizationRegistryCleanupToken) { + cleanupTokenToReactionTrackingMap.delete( + reactionRef.current.finalizationRegistryCleanupToken + ) } }, forceCleanupTimerToRunNowForTests() {