web3-react icon indicating copy to clipboard operation
web3-react copied to clipboard

Lost connect after switch metamask network a few times

Open jxiaox opened this issue 2 years ago • 3 comments

I have use v8 beta for a while, but there is a bug here. Just try these steps:

  1. connect network on demo page(https://web3-react-mu.vercel.app/)
  2. switch network from one to another (eg: Polygon Mainnet to Arbitrum One)
  3. just try step 2 for a few times, the connection is broken

PS: It's ok on v6.

jxiaox avatar Nov 30 '22 06:11 jxiaox

+1 also seeing this issue. Very easily reproducible by switching between polygon and optimism

ohitslaurence avatar Dec 01 '22 10:12 ohitslaurence

I'm still tracking it down, I'll jot down my findings so far.

Only chains that it messes up on. Optimism (10) BSC Testnet (97) Fuji (43113) Mumbai (80001)

All testnets mostly, but Optimism Goerli is fine, and the mainnet messes up.

What I've noticed is when switching to these chains, they do no get flagged as isActivating like the others. Also when switching the chain, the only event that the provider is supposed to call is "chainChanged", but you will see with the ones that mess up, the provider fires events for "disconnect", then "connect", then finally "chainChanged".

This is a MetaMask only bug, Coinbase Wallet is fine. I know MetaMask can miss requests if they are fired off to fast, wonder if it's something like that.

This is a bug in MM and has nothing to do with Web3React. We may be able to do something to reconnect when it happens in this library, but really MM needs to fix their extension. MetaMask github

niZmosis avatar Dec 23 '22 23:12 niZmosis

Have a fix for this in this PR. Ended up catching MM's error on disconnect, and if it is error 1013, I don't reset state for the connector.

niZmosis avatar Dec 24 '22 01:12 niZmosis