MetaMask / MetaMask/metamask-extension
[Bug]: Prerender streams not getting reset
- Dominant language
- TypeScript
- Stars
- 13.2k
- Forks
- 5.6k
- Avg merge
- 2d 5h
- Merged PRs (30d)
- 451
Description
### 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
```shell
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_
Contributor guide
Research direction
Start by reproducing the Chrome pre-load flow on metamask.github.io/test-dapp/, then compare the behavior with the related issue #19290 and its referenced pull request. Inspect the connection and stream lifecycle involved in pre-render navigation, using the “write after end” error as a symptom. Done means pre-load connections and streams no longer affect the active page, and the reported test-dapp steps reconnect without requiring a refresh.
Written by the indexing model from the issue text.
Assessment
- Tech stack
- typescript
- Domain
- frontend
- Issue type
- Bug
- Difficulty
- 4/5
- Estimated time
- 3-5 days
- Activity status
- Stale
- Clarity
- Mostly clear
- Newbie friendliness
- 35/100