Repository navigation
fix(connectors): retry failed metaMask SDK initialization - #5310
Open
hacker14398 wants to merge 1 commit into
Open
hacker14398 wants to merge 1 commit into
hacker14398 wants to merge 1 commit into
Conversation
`getInstance()` cached the `createEVMClient()` promise even when it rejected, so one failed initialization left the connector failing with the same error until the page was reloaded. The promise was also assigned only after `await import()`, so concurrent calls could each create a `MetamaskConnectEVM` client, with each one registering the connector's event handlers. Assign the initialization promise synchronously so concurrent calls share it, and clear it when it rejects so the next call retries. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_01R9CgQNT2zLfeaCLijemCct
|
@hacker14398 is attempting to deploy a commit to the Wevm Team on Vercel. A member of the Team first needs to authorize it. |
🦋 Changeset detectedLatest commit: 1524764 The changes in this PR will be included in the next version bump. This PR includes changesets to release 4 packages
Not sure what this means? Click here to learn what changesets are. Click here if you're a maintainer who wants to add another changeset to this PR |
This branch has not been deployed
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Fixes two problems in the
metaMaskconnector'sgetInstance().1. A failed SDK initialization is cached for the life of the page. If
createEVMClient()rejects, for example from a transient storage or transport error during setup,metamaskPromisekeeps the rejected promise. Every latergetInstance(),getProvider()andconnect()call rethrows the original error, so the connector stays broken until a reload. Because the EIP-6963 pre-connect probes check!metamaskPromise, extension users also lose the injected-provider fast path after one failed attempt.2. Concurrent calls create more than one SDK client.
metamaskPromiseis only assigned afterawait import('@metamask/connect-evm'). So two calls that start before the import resolves both pass the!metamaskPromisecheck, and each callscreateEVMClient(). One example isreconnect()'sgetProvider()probe and a user-initiatedconnect()on a browser without the extension. The multichain core is a singleton, but each call creates a separateMetamaskConnectEVMthat subscribes to it with the connector'seventHandlers. As a result,accountsChanged,display_uriand similar events are delivered twice.Fix: this follows the same pattern as
walletConnect'sinitProvider. The initialization moves into a localinitInstance(). The promise is assigned synchronously, so concurrent callers share it. When it rejects, it is cleared, but only if it is still the current attempt, so the next call retries. Pending and successful initializations are still shared.This is the MetaMask counterpart to #5293 / #5294, which fixes the same retry problem for WalletConnect only.
Most of the diff is re-indentation from moving the existing body into
initInstance(). With whitespace hidden, the source change is +14/−4.Tests (both fail on
main):retries SDK initialization after a failed attempt:createEVMClientrejects once, and the nextgetProvider()resolves instead of rethrowing.creates one SDK client for concurrent calls: two concurrentgetProvider()calls share a singlecreateEVMClient()call.Also ran the connectors test suite,
tsgo --noEmitfor@wagmi/connectors, andbiome check.Written with AI assistance (Claude).