Compare commits
3 Commits
v0.1.0-dev
...
v0.1.0-dev
Author | SHA1 | Date |
---|---|---|
semantic-release-bot | 9dd4f05e9b | |
Derrick Hammer | e574100bb5 | |
Derrick Hammer | 92c18ca940 |
|
@ -1,3 +1,10 @@
|
||||||
|
# [0.1.0-develop.16](https://git.lumeweb.com/LumeWeb/sdk/compare/v0.1.0-develop.15...v0.1.0-develop.16) (2023-10-12)
|
||||||
|
|
||||||
|
|
||||||
|
### Bug Fixes
|
||||||
|
|
||||||
|
* try to avoid unneeded re-rendering if we unmount while in the process of mounting ([92c18ca](https://git.lumeweb.com/LumeWeb/sdk/commit/92c18ca940b3d8651064d58600fdcf83298b305d))
|
||||||
|
|
||||||
# [0.1.0-develop.15](https://git.lumeweb.com/LumeWeb/sdk/compare/v0.1.0-develop.14...v0.1.0-develop.15) (2023-10-12)
|
# [0.1.0-develop.15](https://git.lumeweb.com/LumeWeb/sdk/compare/v0.1.0-develop.14...v0.1.0-develop.15) (2023-10-12)
|
||||||
|
|
||||||
|
|
||||||
|
|
|
@ -1,12 +1,12 @@
|
||||||
{
|
{
|
||||||
"name": "@lumeweb/sdk",
|
"name": "@lumeweb/sdk",
|
||||||
"version": "0.1.0-develop.15",
|
"version": "0.1.0-develop.16",
|
||||||
"lockfileVersion": 3,
|
"lockfileVersion": 3,
|
||||||
"requires": true,
|
"requires": true,
|
||||||
"packages": {
|
"packages": {
|
||||||
"": {
|
"": {
|
||||||
"name": "@lumeweb/sdk",
|
"name": "@lumeweb/sdk",
|
||||||
"version": "0.1.0-develop.15",
|
"version": "0.1.0-develop.16",
|
||||||
"dependencies": {
|
"dependencies": {
|
||||||
"@lumeweb/kernel-network-registry-client": "0.1.0-develop.10",
|
"@lumeweb/kernel-network-registry-client": "0.1.0-develop.10",
|
||||||
"@lumeweb/libkernel": "0.1.0-develop.65",
|
"@lumeweb/libkernel": "0.1.0-develop.65",
|
||||||
|
|
|
@ -1,6 +1,6 @@
|
||||||
{
|
{
|
||||||
"name": "@lumeweb/sdk",
|
"name": "@lumeweb/sdk",
|
||||||
"version": "0.1.0-develop.15",
|
"version": "0.1.0-develop.16",
|
||||||
"type": "module",
|
"type": "module",
|
||||||
"main": "lib/index.js",
|
"main": "lib/index.js",
|
||||||
"types": "lib/src/index.d.ts",
|
"types": "lib/src/index.d.ts",
|
||||||
|
|
|
@ -43,9 +43,10 @@ const LumeContext = createContext<LumeContextType | undefined>(undefined);
|
||||||
|
|
||||||
const LumeProvider = ({ children }) => {
|
const LumeProvider = ({ children }) => {
|
||||||
const [isLoggedIn, setIsLoggedIn] = useState(false);
|
const [isLoggedIn, setIsLoggedIn] = useState(false);
|
||||||
const [ready, setReady] = useState(false);
|
const [ready, setReady] = useState<boolean>(false);
|
||||||
const [lume, setLume] = useState<LumeObject>({ networks: [] });
|
const [lume, setLume] = useState<LumeObject>({ networks: [] });
|
||||||
const statusUnsubs = useRef(new Map());
|
const statusUnsubs = useRef(new Map());
|
||||||
|
const isMounted = useRef(true); // Use a ref to track mounting
|
||||||
|
|
||||||
const handleStatusUpdate = useCallback((id, newNetwork) => {
|
const handleStatusUpdate = useCallback((id, newNetwork) => {
|
||||||
setLume((prevLume) => {
|
setLume((prevLume) => {
|
||||||
|
@ -64,7 +65,6 @@ const LumeProvider = ({ children }) => {
|
||||||
|
|
||||||
for (const type of types) {
|
for (const type of types) {
|
||||||
const list = await networkRegistry.getNetworksByType(type);
|
const list = await networkRegistry.getNetworksByType(type);
|
||||||
|
|
||||||
for (const module of list) {
|
for (const module of list) {
|
||||||
const client = createNetworkClient(module);
|
const client = createNetworkClient(module);
|
||||||
const name = await client.name();
|
const name = await client.name();
|
||||||
|
@ -96,25 +96,29 @@ const LumeProvider = ({ children }) => {
|
||||||
statusUnsubs.current.forEach((unsub) => unsub());
|
statusUnsubs.current.forEach((unsub) => unsub());
|
||||||
statusUnsubs.current = newStatusUnsubs;
|
statusUnsubs.current = newStatusUnsubs;
|
||||||
|
|
||||||
setLume((prevLume) => ({
|
if (isMounted.current) {
|
||||||
...prevLume,
|
setLume((prevLume) => ({
|
||||||
networks: Array.from(newNetworksMap.values()),
|
...prevLume,
|
||||||
}));
|
networks: Array.from(newNetworksMap.values()),
|
||||||
|
}));
|
||||||
|
}
|
||||||
} catch (error) {
|
} catch (error) {
|
||||||
console.error("Error fetching and updating networks:", error);
|
if (isMounted.current) {
|
||||||
|
console.error("Error fetching and updating networks:", error);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
useEffect(() => {
|
useEffect(() => {
|
||||||
fetchAndUpdateNetworks();
|
fetchAndUpdateNetworks();
|
||||||
|
loginComplete().then(() => isMounted.current && setIsLoggedIn(true));
|
||||||
loginComplete().then(() => setIsLoggedIn(true));
|
init().then(() => isMounted.current && setReady(true));
|
||||||
init().then(() => setReady(true));
|
|
||||||
|
|
||||||
const subDone = networkRegistry.subscribeToUpdates(fetchAndUpdateNetworks);
|
const subDone = networkRegistry.subscribeToUpdates(fetchAndUpdateNetworks);
|
||||||
|
|
||||||
return () => {
|
return () => {
|
||||||
subDone();
|
isMounted.current = false; // Track component unmounting
|
||||||
|
subDone?.();
|
||||||
statusUnsubs.current.forEach((unsub) => unsub());
|
statusUnsubs.current.forEach((unsub) => unsub());
|
||||||
};
|
};
|
||||||
}, [fetchAndUpdateNetworks]);
|
}, [fetchAndUpdateNetworks]);
|
||||||
|
|
Loading…
Reference in New Issue