fix: Retry requests from provider after connection is ready, on all builds#24142
fix: Retry requests from provider after connection is ready, on all builds#24142
Conversation
|
CLA Signature Action: All authors have signed the CLA. You may need to manually re-run the blocking PR check if it doesn't pass in a few minutes. |
🔍 Existing Issues For ReviewYour pull request is modifying functions with the following pre-existing issues: 📄 File: app/scripts/background.js
Did you find this useful? React with a 👍 or 👎 |
app/scripts/background.js
Outdated
| console.log(`delaying connection to ${remotePort.sender.url} for 5s`); | ||
| await new Promise((resolve) => setTimeout(resolve, 5000)); | ||
|
|
There was a problem hiding this comment.
this is here to make testing easier. It delays the handling of the dapp responses over the port for 5s.
There was a problem hiding this comment.
TODO: Remove this before approval, of course
There was a problem hiding this comment.
This has been removed, but must be added back locally if you are testing manually
|
Following change in web3-stream-provider needed MetaMask/web3-stream-provider#16 |
b503c8d to
7ae80ba
Compare
Builds ready [9e29f0e]
Page Load Metrics (2874 ± 885 ms)
Bundle size diffs [🚨 Warning! Bundle size has increased!]
|
Codecov ReportAttention: Patch coverage is
Additional details and impacted files@@ Coverage Diff @@
## develop #24142 +/- ##
===========================================
- Coverage 65.70% 65.69% -0.01%
===========================================
Files 1366 1366
Lines 54361 54391 +30
Branches 14141 14144 +3
===========================================
+ Hits 35716 35728 +12
- Misses 18645 18663 +18 ☔ View full report in Codecov by Sentry. |
Builds ready [6513795]
Page Load Metrics (206 ± 223 ms)
|
Builds ready [6921a09]
Page Load Metrics (51 ± 4 ms)
|
Builds ready [6a8083b]
Page Load Metrics (52 ± 3 ms)
|
|
I'm not sure what this is about but I'm seeing some strange inexplicable inconsistency with favicons: |
adonesky1
left a comment
There was a problem hiding this comment.
I'm not seeing the issue with the favicon anymore. I've tested all scenarios (with and without the added delay) and they all look good. Code looks good to me!
Description
Currently, requests from the dapp can hang if:
The inpage provider does have a retry mechanism, but currently that only works on MV3 builds. Additionally, is not a 100% reliable trigger as the underlying
metamask_chainChangedmessage that it relies on is tied to MetaMaskController mem state changes, and is not fired off each time a dapp connection is established.This PR attempts to fix request retries by:
metamask_chainChangedwork on all builds, not just MV3 buildsmetamask_chainChangedevery time a new dapp connection is establishedOpen concern:
There may be an edge case when a request with a confirmation is sent by the dapp, then received and shown to the user in the wallet, but swallowed by prerender. I believe my proposed changes in this PR would cause the confirmation to get resent even though there may still be a confirmation being shown to the user. I haven't been able to test this properly as debugging the prerender issue in general is difficult.
This would require a dapp to send a request requiring confirmation pretty much immediately after page load, implying without user interaction.
Related issues
See: #11069
See: #23329
See: #24025
Manual testing steps
NOTE: these testing steps require that you add an artificial 5s delay to the background connection handling. See the comments below to find the commit where this delay was included in this PR before being removed for merging
Verify this fixes the
metamask_sendDomainMetadataissueVerify this fixes retrying messages before extension is ready
await window.ethereum.request({method: 'eth_chainId'})Verify this fixes retrying messages after broken prerender stream
Not easy to verify this unfortunately, you would need to break the prerender stream while a request was being made
Screenshots/Recordings
Before
After
Pre-merge author checklist
Pre-merge reviewer checklist