MetaMask / metamask-extension

:globe_with_meridians: :electric_plug: The MetaMask browser extension enables browsing Ethereum blockchain enabled websites
https://metamask.io
Other
11.65k stars 4.77k forks source link

[Bug]: Prerender streams not getting reset #23329

Open grothem opened 3 months ago

grothem commented 3 months ago

Describe the bug

This seems to be the issue described in #19290 , but the related PR doesn't seem to fix it for me. It's pretty easy to reproduce on app.aave.com and app.uniswap.org

If I let the pre-render process kick off (in chrome), and then press enter fairly quickly to navigate to a site, the wallet connection will hang, and the only way to get back into a good state is to refresh the app.

I was also able to replicate a similar error on https://metamask.github.io/test-dapp/

Expected behavior

Any connections or streams that happen during a pre-load shouldn't have any impact when the page becomes active.

Screenshots/Recordings

No response

Steps to reproduce

  1. Make sure preloading in chrome is on and set the standard (the default)
  2. Navigate to https://metamask.github.io/test-dapp/
  3. Connect wallet
  4. Open a new tab (do not duplicate) and enter in the same url. If the browser auto-completes, it should start a pre-load process in the background. Note that on the test-dapp site, I have to press enter to navigate almost immediately to see the error, probably because the site content is loaded fast in the pre-render. But on Aave or Uniswap it's a little easier to see the bug.
  5. When the app loads, the account will not be connected and there will be errors in the console. Refreshing the page will reconnect the account

Error messages or log output

Error in event handler: Error: write after end

Version

11.11.0

Build type

None

Browser

Chrome

Operating system

MacOS

Hardware wallet

No response

Additional context

It's hard to debug this running an app locally because pre-load doesn't happen locally. Also, I think with dev tools open that pre-load is disabled.

Severity

No response

gauthierpetetin commented 3 months ago

Potential duplicate of https://github.com/MetaMask/metamask-extension/issues/23336

imajus commented 3 months ago

Potential duplicate of #23336

I honestly doubt that, because the bug occurs only for a new browser instance, and if would you open a new tab with the same page in it, the issue won't be faced there, as opposed to the issue you've referenced.

jtaaa commented 2 months ago

Flagging that OpenSea team is also seeing this issue on opensea.io. It is very easy to reproduce on our site compared to uniswap and aave, likely due to longer pre-load times.

We've spent some time looking into this issue ourselves, although without much results. Would be happy to share any details we have or provide any other support we can to help get this issue resolved.

grothem commented 2 months ago

fwiw we put in a workaround in to try to detect this case. It seems to have helped with most cases, but it does still happen on occasion https://github.com/aave/interface/blob/dfc43dabbe614df77102c3977925c5d7d72f382a/src/libs/web3-data-provider/Web3Provider.tsx#L170

vandan commented 1 month ago

This PR should resolve the issue (as long as they are on a version 120 of Chrome) : https://github.com/MetaMask/metamask-extension/pull/24317

standardimagery commented 3 weeks ago

still there ....…opening a new tab … in BrowserProvider _network [Exception: Error: network is not available yet (code=NETWORK_ERROR…