Compare commits

..

3 Commits

Author SHA1 Message Date
semantic-release-bot 9dd4f05e9b chore(release): 0.1.0-develop.16 [skip ci]
# [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](92c18ca940))
2023-10-12 08:32:10 +00:00
Derrick Hammer e574100bb5
Merge remote-tracking branch 'origin/develop' into develop 2023-10-12 04:30:50 -04:00
Derrick Hammer 92c18ca940
fix: try to avoid unneeded re-rendering if we unmount while in the process of mounting 2023-10-12 04:30:44 -04:00
4 changed files with 25 additions and 14 deletions

View File

@ -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)

4
npm-shrinkwrap.json generated
View File

@ -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",

View File

@ -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",

View File

@ -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]);