connectkit icon indicating copy to clipboard operation
connectkit copied to clipboard

[BUG] `isConnected` always returning false, when clearly connected

Open patrick-streaming opened this issue 10 months ago • 7 comments

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

Image

Whenever I refresh the page, it just keeps saying not connected

To reproduce

  1. 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])
  1. Connect your metamask with a connect button
  2. Refresh the page, it'll always have isConnected be 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

patrick-streaming avatar Feb 04 '25 19:02 patrick-streaming

Doubled checked with rainbowkit, it looks like the same codebase connected to a rainbowkit wallet, returns the correct connected status.

Image

patrick-streaming avatar Feb 04 '25 20:02 patrick-streaming

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)

PatrickAlphaC avatar Feb 07 '25 00:02 PatrickAlphaC

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.

MOZGIII avatar Feb 08 '25 02:02 MOZGIII

yea, if you leave a wallet connected and refresh this bug happens

to-sh-1 avatar Jul 28 '25 19:07 to-sh-1

does this still occur if you set ssr: true in your config?

lochie avatar Jul 28 '25 19:07 lochie

does this still occur if you set ssr: true in 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

to-sh-1 avatar Jul 28 '25 22:07 to-sh-1

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.

pnyda avatar Oct 29 '25 13:10 pnyda