-
Notifications
You must be signed in to change notification settings - Fork 211
perf: defer Solana wallet adapters #1191
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
Open
Xaroz
wants to merge
1
commit into
main
Choose a base branch
from
codex/defer-wallet-runtimes
base: main
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Changes from all commits
Commits
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
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
39 changes: 39 additions & 0 deletions
39
src/features/wallet/context/SolanaWalletAdaptersLoader.tsx
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,39 @@ | ||
| import { SnapWalletAdapter } from '@drift-labs/snap-wallet-adapter'; | ||
| import type { Adapter } from '@solana/wallet-adapter-base'; | ||
| import { | ||
| BackpackWalletAdapter, | ||
| LedgerWalletAdapter, | ||
| PhantomWalletAdapter, | ||
| SalmonWalletAdapter, | ||
| SolflareWalletAdapter, | ||
| TrustWalletAdapter, | ||
| } from '@solana/wallet-adapter-wallets'; | ||
| import { useEffect } from 'react'; | ||
|
|
||
| interface Props { | ||
| onError: (error: unknown) => void; | ||
| onLoad: (adapters: Adapter[]) => void; | ||
| } | ||
|
|
||
| let adapters: Adapter[] | undefined; | ||
|
|
||
| export default function SolanaWalletAdaptersLoader({ onError, onLoad }: Props) { | ||
| useEffect(() => { | ||
| try { | ||
| adapters ??= [ | ||
| new PhantomWalletAdapter(), | ||
| new BackpackWalletAdapter(), | ||
| new SolflareWalletAdapter(), | ||
| new SalmonWalletAdapter(), | ||
| new SnapWalletAdapter(), | ||
| new TrustWalletAdapter(), | ||
| new LedgerWalletAdapter(), | ||
| ]; | ||
| onLoad(adapters); | ||
| } catch (error) { | ||
| onError(error); | ||
| } | ||
| }, [onError, onLoad]); | ||
|
|
||
| return null; | ||
| } |
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,15 @@ | ||
| import { ProtocolType } from '@hyperlane-xyz/utils'; | ||
| import { useConnectFns } from '@hyperlane-xyz/widgets/walletIntegrations/multiProtocol'; | ||
| import { useMemo } from 'react'; | ||
|
|
||
| import { useSolanaWalletActivation } from './context/SolanaWalletContext'; | ||
|
|
||
| export function useAppConnectFns() { | ||
| const connectFns = useConnectFns(); | ||
| const { connect: connectSolana } = useSolanaWalletActivation(); | ||
|
|
||
| return useMemo( | ||
| () => ({ ...connectFns, [ProtocolType.Sealevel]: connectSolana }), | ||
| [connectFns, connectSolana], | ||
| ); | ||
| } |
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.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
🩺 Stability & Availability | 🟠 Major | ⚡ Quick win
🧩 Analysis chain
🏁 Script executed:
Repository: hyperlane-xyz/hyperlane-warp-ui-template
Length of output: 5446
🏁 Script executed:
Repository: hyperlane-xyz/hyperlane-warp-ui-template
Length of output: 9520
🌐 Web query:
@hyperlane-xyz/widgets ErrorBoundary supportLink onError retry API💡 Result:
The
@hyperlane-xyz/widgetspackage contains a component named ErrorBoundary, as evidenced by its registry exports [1]. However, this component is a standard utility component for React applications and does not expose a custom API for supportLink, onError, or retry functionality specifically defined by the Hyperlane library [2][3]. Instead, the@hyperlane-xyz/widgetsErrorBoundary likely follows the implementation pattern of the widely used react-error-boundary library [4], which provides standard props such as: onError: An optional callback invoked when an error is caught, useful for logging error information [4]. resetErrorBoundary (via render props): A function available to fallback components that allows the application to retry rendering after an error [4]. There is no native supportLink prop in standard error boundary patterns; if you require a support link in your fallback UI, you should implement it directly within your custom fallback component passed to the ErrorBoundary [4]. For specialized widget behavior, such as interacting with the Hyperlane bridge, you should refer to the Hyperlane Warp Widget SDK documentation [5], which provides event-based messaging (using onEvent or widget.on) to handle widget lifecycle events like loading and errors [5]. As of 2026, the@hyperlane-xyz/widgetspackage has been migrated into the main hyperlane-monorepo [6].Citations:
🏁 Script executed:
Repository: hyperlane-xyz/hyperlane-warp-ui-template
Length of output: 45775
🌐 Web query:
site:github.com/hyperlane-xyz/hyperlane-monorepo "supportLink" "ErrorBoundary"💡 Result:
There is no standard or widely recognized property, parameter, or component named supportLink associated with React ErrorBoundary in official React documentation or common community patterns. Based on an analysis of public codebases and technical discussions, the term "supportLink" appears in some projects as a custom implementation detail. For instance, in certain UI frameworks or specific monorepo projects, developers may manually create custom error-handling components that include a supportLink prop to direct users to troubleshooting documentation or a support page when an ErrorBoundary catches a runtime exception [1]. If you are encountering this in a specific codebase, it is likely a custom implementation rather than a native React feature. You should check the definition of the component using this prop within your specific project's source code to understand how it is intended to be used, as it is likely passed to a custom UI rendered in the ErrorBoundary's fallback state [1].
Citations:
🌐 Web query:
React.lazy rejected promise retry reset error boundary cached rejection official documentation💡 Result:
In React, React.lazy caches both the returned Promise and its resolved value [1]. If the import Promise rejects, React caches that rejection, meaning subsequent attempts to render the lazy component will continue to throw the same rejection reason [1][2]. Because of this permanent caching behavior, simply trying to re-render the lazy component will not trigger a fresh network request; the failed state persists [2][3][4]. To handle this, the official React documentation recommends using an Error Boundary to catch the loading failure [5]. While the Error Boundary can display an error UI, it cannot natively force React.lazy to "forget" the cached rejection [2][3]. To implement a retry mechanism, you must bypass the internal caching of the lazy component. Common strategies include: 1. Wrapper Functions: Create a custom wrapper for the dynamic import that includes retry logic (e.g., using exponential backoff) [6][7]. Since React.lazy caches the promise, the retry logic must be contained within the function passed to React.lazy so that it manages the retries internally before returning a successful promise to React [6]. 2. Page Refresh: Because React.lazy caches the rejection for the lifetime of the application instance, the most robust way to reset this state is to trigger a full page reload [3][7]. This can be orchestrated within an Error Boundary that detects chunk loading errors and provides a button to refresh the application [3]. 3. Dynamic Component Re-creation: In some specific architectures, you might re-create the lazy component by updating a key or variable that triggers the creation of a new React.lazy instance, effectively forcing a fresh load [2]. However, this is generally more complex to manage than using a retry wrapper or a page refresh [6]. There is currently no built-in "reset" API in React.lazy to clear this cached failure state [2]. [1][2][3][6][5]
Citations:
Handle rejected adapter-chunk imports.
When
lazy(() => import('./SolanaWalletAdaptersLoader'))rejects, the loader never mounts, soonWalletsLoadErrordoes not clearisLoadingorshouldLoadWallets. Add a local error boundary around thisSuspenseboundary. Route the error throughonWalletsLoadError, and make retry recreate the lazy component or reload the page.🤖 Prompt for AI Agents
Source: Coding guidelines