fix(tempo): await accounts import instead of chaining .catch()#5202
Draft
singhlovepreet9 wants to merge 1 commit into
Draft
fix(tempo): await accounts import instead of chaining .catch()#5202singhlovepreet9 wants to merge 1 commit into
singhlovepreet9 wants to merge 1 commit into
Conversation
Chaining .catch() directly on the result of import() assumes that value is always a spec-compliant Promise. Under bundlers where a transformed import() returns a thenable with .then() but no .catch() (e.g. Metro / React Native), evaluating .catch throws "TypeError: undefined is not a function" before the intended error handler ever runs. Await the dynamic import inside try/catch instead, since await only requires a thenable's .then().
|
@singhlovepreet9 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: caf4652 The changes in this PR will be included in the next version bump. This PR includes changesets to release 5 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 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 #5201.
Problem
The Tempo connectors (
webAuthn/tempoWallet/dangerous_secp256k1) in@wagmi/corelazily load the peer-installedaccountspackage with:Chaining
.catch()directly on the result ofimport()assumes that value is always a spec-compliant nativePromise. That isn't guaranteed in every bundling environment — notably under Metro (React Native's bundler), a transformedimport()reliably exposes.then()but not.catch(). Evaluatingimport('accounts').catchthen throwsTypeError: undefined is not a functionbefore the import settles and before the intended'dependency "accounts" not found'message can run, making the connectors unusable there with a misleading error.Fix
Await the dynamic import inside a
try/catchinstead of chaining.catch()on it.awaitonly requires a thenable's.then(), so it works with Metro's non-spec import result while remaining identical for spec Promises. The/* turbopackOptional: true */magic comment and the rethrown error message are preserved.Verification
biome checkon the changed file — clean.tsc --noEmit(core) and thebuild:esm+typesbuild — both pass..thenbut no.catch, mirroring Metro):thenable.catch(...)→TypeError: ...catch is not a functionawait thenable→ resolves normallyNote for reviewers (tests)
The template asks for a test that fails without the fix. I was unable to add one that's meaningful in CI: under Node/Vitest,
import()always returns a spec-compliantPromise(with.catch) andaccountsis installed in the workspace, so both the old and new code behave identically in the test environment — the divergence only appears under Metro's non-specimport()transform, which the repo's test runner can't reproduce. The change is a behavior-preserving 3-line refactor for spec Promises; happy to add a test if you can suggest a way to simulate the Metro import shape within the existing suite.