Skip to content

Fix async injected provider cleanup - #5210

Open
grandpig wants to merge 1 commit into
wevm:mainfrom
grandpig:main
Open

Fix async injected provider cleanup#5210
grandpig wants to merge 1 commit into
wevm:mainfrom
grandpig:main

Conversation

@grandpig

Copy link
Copy Markdown

Summary

  • consolidate the async injected provider event and timeout paths into a single settlement path
  • remove the exact ethereum#initialized listener and clear the timeout once detection settles
  • prevent the losing path from querying the provider after authorization has already completed
  • add regression tests for both timeout-first and event-first behavior

Previously, the listener registered for ethereum#initialized was an anonymous wrapper, while cleanup attempted to remove a different function reference. If the timeout settled first and the event was never emitted, the listener remained attached. If the event settled first, the uncancelled timeout could later perform another provider lookup.

The new settlement path cleans up the listener and timeout before querying the provider and guards against concurrent settlement.

I have tested by the following cmd:

  • pnpm vitest run packages/core/src/connectors/injected.test.ts --project core
  • pnpm --filter @wagmi/core check:types
  • pnpm biome check packages/core/src/connectors/injected.ts packages/core/src/connectors/injected.test.ts .changeset/calm-ravens-listen.md
  • pnpm changeset status

Signed-off-by: grandpig <grandpig@outlook.com>
@changeset-bot

changeset-bot Bot commented Jul 30, 2026

Copy link
Copy Markdown

🦋 Changeset detected

Latest commit: aa4fb33

The changes in this PR will be included in the next version bump.

This PR includes changesets to release 5 packages
Name Type
@wagmi/core Patch
@wagmi/connectors Patch
wagmi Patch
@wagmi/solid Patch
@wagmi/vue Patch

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

@grandpig

Copy link
Copy Markdown
Author

@tmm Hi! Would you mind taking a look at this when you have a chance? It fixes cleanup of the async injected-provider detection path and adds regression tests for both timeout-first and event-first cases. Thanks!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant