[BUG] `isConnected` always returning false, when clearly connected
Describe the bug
I have the following code:
'use client'
import { useEffect, useState } from 'react'
import { useAccount } from 'wagmi'
export default function Home() {
const { isConnected, address, status } = useAccount()
useEffect(() => {
console.log(isConnected)
console.log(address)
console.log(status)
}, [isConnected, address, status])
And on my UI, Metamask is clearly connected (my metamask, show it's connected to the site, and you can see the address of my metamask being console.logged out):
Whenever I refresh the page, it just keeps saying not connected
To reproduce
- Use the
import { useAccount } from 'wagmi'hook, and in a component, add:
export default function Home() {
const { isConnected, address, status } = useAccount()
useEffect(() => {
console.log(isConnected)
console.log(address)
console.log(status)
}, [isConnected, address, status])
- Connect your metamask with a
connectbutton - Refresh the page, it'll always have
isConnectedbe false
Optionally, you can see this repo for more information.
Expected behavior
isConnected should be true, as my Metamask says it's true
Screenshots
See above
Environment details
nodejs: v23.5.0 "wagmi": "^2.14.9" "connectkit": "^1.8.2",
Tagging @patrickalphac
Doubled checked with rainbowkit, it looks like the same codebase connected to a rainbowkit wallet, returns the correct connected status.
After trying to reproduce this error, I'm unable to.
I'll close for now.
(Whoops, I'm on my wrong account, I'll have to switch)
We see the same in our tests. Looks like connectkit does not initialize the state properly, i.e. assumes wagmi can't be connected at initialization, or sth.
yea, if you leave a wallet connected and refresh this bug happens
does this still occur if you set ssr: true in your config?
does this still occur if you set
ssr: truein your config?
yes. My config looks like
export const config = createConfig(
getDefaultConfig({
chains: [base],
transports: {
[base.id]: http(),
},
enableFamily: false,
ssr: true,
})
);
and if I connect and then refresh, it will show my address and if I select it will ask me to select a wallet instead of the disconnect screen. It also shows that I'm not connecting and the status is "is connecting" before I even select anything
This bug is killing me 🥺 I confirmed that this reproduces on iOS Phantom in-wallet browser and iOS Rainbow in-wallet browser. But it doesn't reproduce on Family iOS in-wallet browser.