Skip to content

[SDK] Fix onDisconnect callback not being invoked in React Native #7850

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

Conversation

joaquim-verges
Copy link
Member

@joaquim-verges joaquim-verges commented Aug 13, 2025

Fixes #7830


PR-Codex overview

This PR addresses an issue where the onDisconnect function was not being invoked in the DisconnectWallet component of the React Native application. It modifies the component to include this functionality, ensuring proper disconnection handling.

Detailed summary

  • Updated DisconnectWallet component to include onDisconnect in props.
  • Invoked onDisconnect with wallet and account parameters when the disconnect process is triggered.

✨ Ask PR-Codex anything about this PR by commenting with /codex {your question}

Summary by CodeRabbit

  • New Features

    • Added an optional onDisconnect callback to the React Native wallet connection modal, invoked after the standard disconnect/logout sequence.
  • Bug Fixes

    • Resolved an issue where onDisconnect was not being invoked in React Native after disconnecting a wallet.
  • Chores

    • Added a changeset to publish a patch release documenting the fix.

Copy link

vercel bot commented Aug 13, 2025

The latest updates on your projects. Learn more about Vercel for Git ↗︎

Project Deployment Preview Comments Updated (UTC)
docs-v2 Ready Preview Comment Aug 13, 2025 1:03am
nebula Ready Preview Comment Aug 13, 2025 1:03am
thirdweb_playground Ready Preview Comment Aug 13, 2025 1:03am
thirdweb-www Ready Preview Comment Aug 13, 2025 1:03am
wallet-ui Ready Preview Comment Aug 13, 2025 1:03am

Copy link

changeset-bot bot commented Aug 13, 2025

🦋 Changeset detected

Latest commit: 83c9ac4

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

This PR includes changesets to release 3 packages
Name Type
thirdweb Patch
@thirdweb-dev/nebula Patch
@thirdweb-dev/wagmi-adapter 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

Copy link
Contributor

coderabbitai bot commented Aug 13, 2025

Walkthrough

Adds a changeset for a patch release documenting a React Native fix. Updates ConnectedModal in React Native to accept an optional onDisconnect callback and invokes it after the existing disconnect flow.

Changes

Cohort / File(s) Summary
Release/Changeset
/.changeset/many-tips-fail.md
Adds a changeset marking a patch for “thirdweb” noting a fix for onDisconnect not being invoked in React Native. No code changes.
React Native Connect Modal
packages/thirdweb/src/react/native/ui/connect/ConnectedModal.tsx
Adds optional prop onDisconnect?: (payload: { wallet: Wallet; account: Account }) => void and invokes it after onClose, disconnect, and optional siweAuth.doLogout within DisconnectWallet flow.

Sequence Diagram(s)

sequenceDiagram
  autonumber
  actor User
  participant ConnectedModal
  participant Wallet as WalletManager
  participant SIWE as SIWEAuth
  participant App as App(Consumer)

  User->>ConnectedModal: Trigger Disconnect
  ConnectedModal->>ConnectedModal: onClose()
  ConnectedModal->>Wallet: disconnect(wallet)
  alt SIWE session exists
    ConnectedModal->>SIWE: doLogout()
  end
  opt onDisconnect provided
    ConnectedModal->>App: onDisconnect({ wallet, account })
  end
Loading

Estimated code review effort

🎯 2 (Simple) | ⏱️ ~8 minutes

Warning

Review ran into problems

🔥 Problems

Errors were encountered while retrieving linked issues.

Errors (1)
  • TEAM-0000: Entity not found: Issue - Could not find referenced Issue.
✨ Finishing Touches
  • 📝 Generate Docstrings
🧪 Generate unit tests
  • Create PR with unit tests
  • Post copyable unit tests in a comment
  • Commit unit tests in branch _React_Native_Fix_onDisconnect_callback_not_being_invoked

🪧 Tips

Chat

There are 3 ways to chat with CodeRabbit:

  • Review comments: Directly reply to a review comment made by CodeRabbit. Example:
    • I pushed a fix in commit <commit_id>, please review it.
    • Open a follow-up GitHub issue for this discussion.
  • Files and specific lines of code (under the "Files changed" tab): Tag @coderabbitai in a new review comment at the desired location with your query.
  • PR comments: Tag @coderabbitai in a new PR comment to ask questions about the PR branch. For the best results, please provide a very specific query, as very limited context is provided in this mode. Examples:
    • @coderabbitai gather interesting stats about this repository and render them as a table. Additionally, render a pie chart showing the language distribution in the codebase.
    • @coderabbitai read the files in the src/scheduler package and generate a class diagram using mermaid and a README in the markdown format.

Support

Need help? Create a ticket on our support page for assistance with any issues or questions.

CodeRabbit Commands (Invoked using PR/Issue comments)

Type @coderabbitai help to get the list of available commands.

Other keywords and placeholders

  • Add @coderabbitai ignore anywhere in the PR description to prevent this PR from being reviewed.
  • Add @coderabbitai summary to generate the high-level summary at a specific location in the PR description.
  • Add @coderabbitai anywhere in the PR title to generate the title automatically.

CodeRabbit Configuration File (.coderabbit.yaml)

  • You can programmatically configure CodeRabbit by adding a .coderabbit.yaml file to the root of your repository.
  • Please see the configuration documentation for more information.
  • If your editor has YAML language server enabled, you can add the path at the top of this file to enable auto-completion and validation: # yaml-language-server: $schema=https://coderabbit.ai/integrations/schema.v2.json

Status, Documentation and Community

  • Visit our Status Page to check the current availability of CodeRabbit.
  • Visit our Documentation for detailed information on how to use CodeRabbit.
  • Join our Discord Community to get help, request features, and share feedback.
  • Follow us on X/Twitter for updates and announcements.

@github-actions github-actions bot added packages SDK Involves changes to the thirdweb SDK labels Aug 13, 2025
Copy link
Member Author


How to use the Graphite Merge Queue

Add either label to this PR to merge it via the merge queue:

  • merge-queue - adds this PR to the back of the merge queue
  • hotfix - for urgent hot fixes, skip the queue and merge this PR next

You must have a Graphite account in order to use the merge queue. Sign up using this link.

An organization admin has enabled the Graphite Merge Queue in this repository.

Please do not merge from GitHub as this will restart CI on PRs being processed by the merge queue.

This stack of pull requests is managed by Graphite. Learn more about stacking.

@joaquim-verges joaquim-verges changed the title [React Native] Fix onDisconnect callback not being invoked [SDK] Fix onDisconnect callback not being invoked in React Native Aug 13, 2025
@joaquim-verges joaquim-verges marked this pull request as ready for review August 13, 2025 00:48
@joaquim-verges joaquim-verges requested review from a team as code owners August 13, 2025 00:48
Copy link
Contributor

@coderabbitai coderabbitai bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Actionable comments posted: 0

🔭 Outside diff range comments (1)
packages/thirdweb/src/react/native/ui/connect/ConnectedModal.tsx (1)

49-55: onDisconnect prop missing from ConnectedModalProps type.

You destructure onDisconnect later but ConnectedModalProps doesn’t declare it, which will cause a TypeScript error.

Add the optional callback to the prop type:

 type ConnectedModalProps = ConnectButtonProps & {
   theme: Theme;
   wallet: Wallet;
   account: Account;
   onClose?: () => void;
   containerType: ContainerType;
+  onDisconnect?: (payload: { wallet: Wallet; account: Account }) => void;
 };
🧹 Nitpick comments (2)
.changeset/many-tips-fail.md (1)

5-5: Polish changeset copy for clarity and capitalization.

Recommend clarifying the scope and capitalizing “React Native”.

Apply this diff:

-Fix onDisconnect not being invoked in react native
+Fix onDisconnect callback not being invoked in React Native ConnectedModal
packages/thirdweb/src/react/native/ui/connect/ConnectedModal.tsx (1)

301-311: Ensure onDisconnect fires after disconnect/logout completes; guard against callback errors.

Current flow calls onDisconnect immediately (and potentially before async disconnect/logout complete). Consider running the sequence asynchronously, awaiting disconnect/logout, and invoking onDisconnect in a finally to guarantee it runs. Also guard against exceptions in user callbacks to avoid crashing the UI.

Apply this diff:

-      onPress={() => {
-        onClose?.();
-        disconnect(wallet);
-        if (siweAuth.isLoggedIn) {
-          siweAuth.doLogout();
-        }
-        onDisconnect?.({
-          wallet,
-          account,
-        });
-      }}
+      onPress={() => {
+        onClose?.();
+        void (async () => {
+          try {
+            await disconnect(wallet);
+            if (siweAuth.isLoggedIn) {
+              await siweAuth.doLogout();
+            }
+          } finally {
+            try {
+              onDisconnect?.({ wallet, account });
+            } catch {
+              // Swallow user callback errors to avoid crashing the UI
+            }
+          }
+        })();
+      }}
📜 Review details

Configuration used: CodeRabbit UI
Review profile: CHILL
Plan: Pro

📥 Commits

Reviewing files that changed from the base of the PR and between 74d4074 and 83c9ac4.

📒 Files selected for processing (2)
  • .changeset/many-tips-fail.md (1 hunks)
  • packages/thirdweb/src/react/native/ui/connect/ConnectedModal.tsx (2 hunks)
🧰 Additional context used
📓 Path-based instructions (2)
**/*.{ts,tsx}

📄 CodeRabbit Inference Engine (CLAUDE.md)

**/*.{ts,tsx}: Write idiomatic TypeScript with explicit function declarations and return types
Limit each file to one stateless, single-responsibility function for clarity
Re-use shared types from @/types or local types.ts barrels
Prefer type aliases over interface except for nominal shapes
Avoid any and unknown unless unavoidable; narrow generics when possible
Choose composition over inheritance; leverage utility types (Partial, Pick, etc.)
Comment only ambiguous logic; avoid restating TypeScript in prose

Files:

  • packages/thirdweb/src/react/native/ui/connect/ConnectedModal.tsx
**/*.{ts,tsx,js,jsx}

📄 CodeRabbit Inference Engine (CLAUDE.md)

Load heavy dependencies inside async paths to keep initial bundle lean (lazy loading)

Files:

  • packages/thirdweb/src/react/native/ui/connect/ConnectedModal.tsx
⏰ Context from checks skipped due to timeout of 90000ms. You can increase the timeout in your CodeRabbit configuration to a maximum of 15 minutes (900000ms). (8)
  • GitHub Check: E2E Tests (pnpm, webpack)
  • GitHub Check: E2E Tests (pnpm, vite)
  • GitHub Check: E2E Tests (pnpm, esbuild)
  • GitHub Check: Size
  • GitHub Check: Build Packages
  • GitHub Check: Unit Tests
  • GitHub Check: Lint Packages
  • GitHub Check: Analyze (javascript)
🔇 Additional comments (2)
packages/thirdweb/src/react/native/ui/connect/ConnectedModal.tsx (2)

296-296: Destructuring onDisconnect here is correct once prop typing is updated.

After adding onDisconnect to ConnectedModalProps, this destructuring is good.


301-304: No action needed: onClose before onDisconnect is deliberate and consistent
We verified that in the React Native ConnectedModal and in the web ConnectedWalletDetails modal, the modal is closed (via onClose/closeModal) before invoking the consumer’s onDisconnect callback. This matches the established pattern across platforms, so the current ordering can remain as is.

Copy link
Contributor

size-limit report 📦

Path Size Loading time (3g) Running time (snapdragon) Total time
thirdweb (esm) 64.06 KB (0%) 1.3 s (0%) 173 ms (+106.43% 🔺) 1.5 s
thirdweb (cjs) 357.05 KB (0%) 7.2 s (0%) 656 ms (+7.55% 🔺) 7.8 s
thirdweb (minimal + tree-shaking) 5.73 KB (0%) 115 ms (0%) 53 ms (+713.89% 🔺) 167 ms
thirdweb/chains (tree-shaking) 526 B (0%) 11 ms (0%) 54 ms (+3391.23% 🔺) 64 ms
thirdweb/react (minimal + tree-shaking) 19.15 KB (0%) 383 ms (0%) 72 ms (+426.04% 🔺) 455 ms

Copy link

codecov bot commented Aug 13, 2025

Codecov Report

✅ All modified and coverable lines are covered by tests.
✅ Project coverage is 56.34%. Comparing base (74d4074) to head (83c9ac4).
⚠️ Report is 1 commits behind head on main.

Additional details and impacted files
@@           Coverage Diff           @@
##             main    #7850   +/-   ##
=======================================
  Coverage   56.34%   56.34%           
=======================================
  Files         905      905           
  Lines       58834    58834           
  Branches     4150     4152    +2     
=======================================
  Hits        33151    33151           
  Misses      25577    25577           
  Partials      106      106           
Flag Coverage Δ
packages 56.34% <ø> (ø)
🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.
  • 📦 JS Bundle Analysis: Save yourself from yourself by tracking and limiting bundle sizes in JS merges.

@joaquim-verges joaquim-verges merged commit 4be655d into main Aug 13, 2025
27 checks passed
@joaquim-verges joaquim-verges deleted the _React_Native_Fix_onDisconnect_callback_not_being_invoked branch August 13, 2025 01:18
@joaquim-verges joaquim-verges mentioned this pull request Aug 13, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
packages SDK Involves changes to the thirdweb SDK
Projects
None yet
Development

Successfully merging this pull request may close these issues.

ConnectButton onDisconnect event is not fired
1 participant