solana-mobile / mobile-wallet-adapter

Other
249 stars 104 forks source link

[wallet-adapter-mobile] React tree does not re-render when disconnect is called #202

Closed steveluscher closed 2 years ago

steveluscher commented 2 years ago

Repro

  1. Open the example web app
  2. Connect the wallet
  3. Click disconnect

Observe that the disconnect happens and the user's balance gets zeroed out, but the React tree does not rerender (so the pubkey does not become null) and now your UI is in an inconsistent state.

There's just a race condition somewhere. Probably the event that listens to disconnect is getting unhooked before the disconnect event is fired. Something like that.

https://user-images.githubusercontent.com/13243/183160402-ced3c2a2-3664-4af3-ac1b-018b4dfab8f2.mov

steveluscher commented 2 years ago

OK, I figured out why this is.

On desktop web, we never ‘leave’ the webpage; all interaction with the wallet happens between the browser's JS context and the browser extension.

On mobile web, every time we trigger the solana-wallet:// Universal Link, the browser's beforeunload event fires. Our code currently kneecaps disconnect events if they are received during the period where we believe that the browser is unloading.

cc/ @jordansexton.

jordaaash commented 2 years ago

Ah, makes sense + good find. We could find a way to special case that code when the selected adapter is MWA?

steveluscher commented 2 years ago

Closed by https://github.com/solana-labs/wallet-adapter/commit/c1e1fc91871ad3431c1a6ead67b17ed05843241e.