From 03434b43292463602526ec590327e384a10e5f75 Mon Sep 17 00:00:00 2001 From: Derrick Hammer Date: Thu, 12 Oct 2023 04:40:08 -0400 Subject: [PATCH] fix: abort and unsub if we unmount inside the loop, and check after the loop as well --- src/components/lume/LumeProvider.tsx | 11 +++++++++++ 1 file changed, 11 insertions(+) diff --git a/src/components/lume/LumeProvider.tsx b/src/components/lume/LumeProvider.tsx index 1d247b9..62181ca 100644 --- a/src/components/lume/LumeProvider.tsx +++ b/src/components/lume/LumeProvider.tsx @@ -58,12 +58,21 @@ const LumeProvider = ({ children }) => { }, []); const fetchAndUpdateNetworks = async () => { + const unsub = () => { + statusUnsubs.current.forEach((unsub) => unsub()); + statusUnsubs.current = new Map(); + }; + try { const types = await networkRegistry.getTypes(); const newNetworksMap = new Map(); const newStatusUnsubs = new Map(); for (const type of types) { + if (!isMounted.current) { + unsub(); + return; + } const list = await networkRegistry.getNetworksByType(type); for (const module of list) { const client = createNetworkClient(module); @@ -101,6 +110,8 @@ const LumeProvider = ({ children }) => { ...prevLume, networks: Array.from(newNetworksMap.values()), })); + } else { + unsub(); } } catch (error) { if (isMounted.current) {