Skip to content

Conversation

@jordaaash
Copy link
Collaborator

Fixes #636

Now that we're not wiping the state when the adapter changes, we'll need to check the logic in all the other places this should happen.

@changeset-bot
Copy link

changeset-bot bot commented Oct 29, 2022

🦋 Changeset detected

Latest commit: a704afb

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

This PR includes changesets to release 4 packages
Name Type
@solana/wallet-adapter-react Patch
@solana/wallet-adapter-ant-design Patch
@solana/wallet-adapter-material-ui Patch
@solana/wallet-adapter-react-ui 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

@steveluscher
Copy link
Collaborator

steveluscher commented Oct 29, 2022

Instead, let's try to store the actual error handler in a ref, update that ref in an effect, so then we can remove the handler as a dep of handleFoo. We might have to be careful to blank out the ref when the component unmounts so as to avoid memory leaks, maybe. Haven't looked too closely.

Copy link
Collaborator

@steveluscher steveluscher left a comment

Choose a reason for hiding this comment

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

"dependencies" amirite?

@steveluscher
Copy link
Collaborator

handleError won't even need to useCallback after you've done this since both of the things it uses will be refs.

@jordaaash
Copy link
Collaborator Author

Yeah, sounds good. Will update and test.

@steveluscher
Copy link
Collaborator

Wrote a failing test for you: 2c17fc6.

@steveluscher
Copy link
Collaborator

Ooh! This is even better. When you fix the bug, you'll find that another test breaks, pointing to a separate real problem that this was masking.

I don't want to steal it from you, but please do let me know if you want me to take this over.

@jordaaash jordaaash merged commit 0667d6d into master Oct 29, 2022
@jordaaash jordaaash deleted the fix-onerror branch October 29, 2022 22:29
@jordaaash
Copy link
Collaborator Author

Yeah, turned out we need that state reset when the adapter changes, at minimum to wipe out the publicKey. I refactored a bit and did the ref thing. I went ahead and merged to get a fixed release out but if it doesn't look ideal, please revise!

@github-actions github-actions bot mentioned this pull request Oct 29, 2022
@jordaaash jordaaash changed the title Don't reset state when adapter or onError changes Don't reset state when onError changes Oct 29, 2022
@@ -1,4 +1,4 @@
import type { WalletName } from '@solana/wallet-adapter-base';
import { type WalletName } from '@solana/wallet-adapter-base';
Copy link
Collaborator

Choose a reason for hiding this comment

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

🧐

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

It was getting annoying to have two imports for the same dependencies everywhere. 😅

}, [adapter, setWalletName]);
return (
<WalletProviderBase
{...props}
Copy link
Collaborator

Choose a reason for hiding this comment

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

y tho? I did this so that any additions to WalletProvider would get caught as TS errors if they were forgotten in Base.

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

Yeah, I could see that, but it makes things a bit more complicated for the sake of something that almost never happens. When do we add props to the WalletProvider, and how likely are we to forget to use them if we need them?

onAutoConnectRequest,
onConnectError,
onError,
onError = (error, adapter) => {
Copy link
Collaborator

Choose a reason for hiding this comment

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

I think this will result in a new copy of this function on every render, which will thrash the effect.

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

Ahh, you're probably right.

handleErrorRef.current = (error, adapter) => {
if (!isUnloadingRef.current) {
if (onError) {
onError(error, adapter);
Copy link
Collaborator

@steveluscher steveluscher Oct 29, 2022

Choose a reason for hiding this comment

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

If you make the call to handleErrorRef.current here, all of the rest of the code gets way simpler.

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

Good point, I wasn't happy with how I did this.

@jordaaash jordaaash mentioned this pull request Oct 30, 2022
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.

Updating WalletProvider.onError prop incorrectly disconnects the adapter

3 participants