-
Notifications
You must be signed in to change notification settings - Fork 222
Open
Labels
bugSomething isn't workingSomething isn't working
Description
Issue Description
When using ConnectKit, we discovered a problem of Wagmi storage pollution, which leads to inconsistent chain states. Specifically:
- Multiple Wagmi storage keys appear in the app (e.g.,
wagmi.storeand a custom storage key) - After a user manually switches the chain, it reverts to the default chain (Ethereum mainnet) upon reloading the page
- Chain state appears inconsistent across different components
Root Cause
After debugging, we found that the issue originates from the internal useEnsFallbackConfig hook inside ConnectKit (located at packages/connectkit/src/hooks/useEnsFallbackConfig.ts).
The relevant code:
import { http, createConfig } from 'wagmi';
import { mainnet } from 'wagmi/chains';
const ensFallbackConfig = createConfig({
chains: [mainnet],
transports: {
[mainnet.id]: http(),
},
});
export function useEnsFallbackConfig(): Config | undefined {
return !useChainIsSupported(1) ? ensFallbackConfig : undefined;
}This internal configuration:
- Creates a separate Wagmi instance, even when the app already provides a custom Wagmi configuration
- Uses the default storage key, resulting in the coexistence of
wagmi.storeand the custom storage key - Interferes with chain state management — when this fallback config is activated, it can override the user’s manually selected chain
Steps to Reproduce
-
Configure ConnectKit and Wagmi, setting a custom storage key and default chain (e.g., BSC chain with ID 56).
-
Manually connect a wallet and switch to the BSC chain.
-
Refresh or reopen the app.
-
Observe the behavior: the app reconnects to Ethereum mainnet (chain ID 1).
-
Check
localStorage:wagmi.storecontains chain ID 1- Custom storage key contains chain ID 56
Expected Behavior
- The app should use the user-provided Wagmi configuration and storage settings.
- Chain state should remain consistent and unaffected by any internal fallback config.
- The user’s manual chain selection should be correctly persisted across sessions.
Metadata
Metadata
Assignees
Labels
bugSomething isn't workingSomething isn't working