-
Notifications
You must be signed in to change notification settings - Fork 673
[SDK] fix: ignore EIP-1193 code 1013 transient disconnect in injected… #8807
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
0xFirekeeper
merged 6 commits into
main
from
sdk/fix-injected-wallet-1013-transient-disconnect
Jun 15, 2026
Merged
Changes from all commits
Commits
Show all changes
6 commits
Select commit
Hold shift + click to select a range
13e3419
[SDK] fix: ignore EIP-1193 code 1013 transient disconnect in injected…
Yash094 ca6d8cc
[SDK] fix: export WalletDisconnectError and use shared type in onDisc…
Yash094 f305169
[SDK] fix: format import in injected/index.ts
Yash094 5464d7a
Increase test max-old-space-size to 12288
0xFirekeeper 805ee90
Update mintableERC721.test.ts
0xFirekeeper 2628e3d
tests
0xFirekeeper File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
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
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,7 @@ | ||
| --- | ||
| "thirdweb": patch | ||
| --- | ||
|
|
||
| Fix: injected wallets (e.g. MetaMask) no longer fire a spurious `"disconnect"` event for transient EIP-1193 error code 1013 ("disconnected, will reconnect"). Previously, MetaMask's temporary disconnect during chain changes or RPC hiccups would trigger the thirdweb `disconnect` subscriber and tear down wallet state, causing unexpected logouts. The `onDisconnect` handler now ignores code-1013 errors and lets MetaMask reconnect automatically. | ||
|
|
||
| Additionally, the `WalletEmitterEvents["disconnect"]` type is updated from `never` to `WalletDisconnectError | undefined`, so `disconnect` subscribers can inspect the underlying EIP-1193 error code and message when they need to distinguish disconnect causes. |
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
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
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
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
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
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,87 @@ | ||
| import type { EIP1193Provider } from "viem"; | ||
| import { describe, expect, it, vi } from "vitest"; | ||
| import { TEST_ACCOUNT_A } from "~test/test-wallets.js"; | ||
| import { TEST_CLIENT } from "../../../test/src/test-clients.js"; | ||
| import { | ||
| createWalletEmitter, | ||
| type WalletDisconnectError, | ||
| } from "../wallet-emitter.js"; | ||
| import { autoConnectEip1193Wallet } from "./index.js"; | ||
|
|
||
| describe("injected wallet onDisconnect", () => { | ||
| // biome-ignore lint/suspicious/noExplicitAny: test listener registry | ||
| type Listener = (...args: any[]) => void; | ||
|
|
||
| async function connectAndGetDisconnectHandler() { | ||
| let disconnectHandler: | ||
| | ((error?: WalletDisconnectError) => void) | ||
| | undefined; | ||
|
|
||
| const provider = { | ||
| on: vi.fn((event: string, listener: Listener) => { | ||
| if (event === "disconnect") { | ||
| disconnectHandler = listener; | ||
| } | ||
| }), | ||
| removeListener: vi.fn(), | ||
| request: vi.fn(async ({ method }: { method: string }) => { | ||
| if (method === "eth_accounts") { | ||
| return [TEST_ACCOUNT_A.address]; | ||
| } | ||
| if (method === "eth_chainId") { | ||
| return "0x1"; | ||
| } | ||
| return undefined; | ||
| }), | ||
| } as unknown as EIP1193Provider; | ||
|
|
||
| const emitter = createWalletEmitter<"io.metamask">(); | ||
| const onDisconnect = vi.fn(); | ||
| emitter.subscribe("disconnect", onDisconnect); | ||
|
|
||
| await autoConnectEip1193Wallet({ | ||
| client: TEST_CLIENT, | ||
| emitter, | ||
| id: "io.metamask", | ||
| provider, | ||
| }); | ||
|
|
||
| if (!disconnectHandler) { | ||
| throw new Error("disconnect handler was not registered"); | ||
| } | ||
|
|
||
| return { disconnectHandler, onDisconnect, provider }; | ||
| } | ||
|
|
||
| it("ignores transient 1013 disconnects (disconnected, will reconnect)", async () => { | ||
| const { disconnectHandler, onDisconnect, provider } = | ||
| await connectAndGetDisconnectHandler(); | ||
|
|
||
| await disconnectHandler({ code: 1013, message: "will reconnect" }); | ||
|
|
||
| expect(onDisconnect).not.toHaveBeenCalled(); | ||
| expect(provider.removeListener).not.toHaveBeenCalled(); | ||
| }); | ||
|
|
||
| it("emits disconnect with the error for non-transient disconnects", async () => { | ||
| const { disconnectHandler, onDisconnect } = | ||
| await connectAndGetDisconnectHandler(); | ||
|
|
||
| const error: WalletDisconnectError = { | ||
| code: 4900, | ||
| message: "disconnected", | ||
| }; | ||
| await disconnectHandler(error); | ||
|
|
||
| expect(onDisconnect).toHaveBeenCalledWith(error); | ||
| }); | ||
|
|
||
| it("emits disconnect with undefined when no error is provided", async () => { | ||
| const { disconnectHandler, onDisconnect } = | ||
| await connectAndGetDisconnectHandler(); | ||
|
|
||
| await disconnectHandler(); | ||
|
|
||
| expect(onDisconnect).toHaveBeenCalledWith(undefined); | ||
| }); | ||
| }); |
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
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
Oops, something went wrong.
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.
Uh oh!
There was an error while loading. Please reload this page.