-
Notifications
You must be signed in to change notification settings - Fork 176
fix: remove async from void onPress callback (SonarCloud bug) #174
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
base: main
Are you sure you want to change the base?
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -104,9 +104,11 @@ export const RemoteServersScreen: React.FC = () => { | |
| { | ||
| text: 'Delete', | ||
| style: 'destructive', | ||
| onPress: async () => { | ||
| onPress: () => { | ||
| if (activeServerId === server.id) setActiveServerId(null); | ||
| await remoteServerManager.removeServer(server.id); | ||
| remoteServerManager.removeServer(server.id).catch(error => | ||
| setAlertState(showAlert('Deletion Failed', error instanceof Error ? error.message : 'An unknown error occurred.')) | ||
| ); | ||
| }, | ||
|
Comment on lines
+107
to
112
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. While removing This violates a general project rule: "Use To fix this, you should add a References
Owner
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Good catch — added |
||
| }, | ||
| ] | ||
|
|
||
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.
There's a potential race condition here. If the component unmounts after the delete operation starts but before it completes (e.g., the user navigates away quickly),
setAlertStatecould be called on an unmounted component. This would result in a React warning about memory leaks.To prevent this, you can use a
useRefto track if the component is mounted.First, add this to your component:
Then, check this ref in your
.catchblock before callingsetAlertState: