From 7b61fd664daa256578c092e8feef6e4b1f25931d Mon Sep 17 00:00:00 2001 From: Michael Moldoveanu Date: Thu, 17 Oct 2024 12:26:56 -0400 Subject: [PATCH] fix: issue causing recursive depth exception in react (#1088) --- account-kit/core/src/store/store.test.ts | 4 ++-- account-kit/core/src/store/store.ts | 14 ++++++++------ 2 files changed, 10 insertions(+), 8 deletions(-) diff --git a/account-kit/core/src/store/store.test.ts b/account-kit/core/src/store/store.test.ts index 6018fae420..c22ffe2076 100644 --- a/account-kit/core/src/store/store.test.ts +++ b/account-kit/core/src/store/store.test.ts @@ -104,7 +104,7 @@ describe("createConfig tests", () => { "status": "INITIALIZING", }, }, - "version": 12, + "version": 13, } `); }); @@ -173,7 +173,7 @@ describe("createConfig tests", () => { "status": "INITIALIZING", }, }, - "version": 12, + "version": 13, } `); }); diff --git a/account-kit/core/src/store/store.ts b/account-kit/core/src/store/store.ts index da990e05d0..3fb082e481 100644 --- a/account-kit/core/src/store/store.ts +++ b/account-kit/core/src/store/store.ts @@ -70,11 +70,9 @@ export const createAccountKitStore = ( }, reviver: (key, value) => { if (key === "chain") { - return ( - connections.find( - (c) => c.chain.id === (value as { id: number }).id - )?.chain ?? connections[0].chain - ); + return connections.find( + (c) => c.chain.id === (value as { id: number }).id + )?.chain; } return storeReviver(key, value); @@ -82,6 +80,10 @@ export const createAccountKitStore = ( }), merge: (persisted, current) => { const persistedState = persisted as StoreState; + if (persistedState.chain == null) { + return createInitialStoreState(params); + } + const connectionsMap = createConnectionsMap(connections); if (!connectionsMap.has(persistedState.chain.id)) { return createInitialStoreState(params); @@ -107,7 +109,7 @@ export const createAccountKitStore = ( skipHydration: ssr, partialize: ({ signer, accounts, ...writeableState }) => writeableState, - version: 12, + version: 13, }) : () => createInitialStoreState(params) )