betodealmeida commented on code in PR #35810:
URL: https://github.com/apache/superset/pull/35810#discussion_r2582870987
##########
superset-frontend/src/components/Datasource/components/DatasourceEditor/DatasourceEditor.jsx:
##########
@@ -765,16 +767,22 @@ class DatasourceEditor extends PureComponent {
try {
const response = await this.props.formatQuery(datasource.sql);
- this.onDatasourcePropChange('sql', response.json.result);
- this.props.addSuccessToast(t('SQL was formatted'));
+
+ if (this.isComponentMounted) {
Review Comment:
Same for
`superset-frontend/src/components/Datasource/components/DatasourceEditor/components/DatasetUsageTab/index.tsx`.
##########
superset-frontend/src/components/Datasource/components/DatasourceEditor/DatasourceEditor.jsx:
##########
@@ -765,16 +767,22 @@ class DatasourceEditor extends PureComponent {
try {
const response = await this.props.formatQuery(datasource.sql);
- this.onDatasourcePropChange('sql', response.json.result);
- this.props.addSuccessToast(t('SQL was formatted'));
+
+ if (this.isComponentMounted) {
Review Comment:
I'm worried about all these `if (this.isComponentMounted)` checks being
added, it looks like an anti-pattern for me. Can't we use an `AbortController`
here instead?
Something like (untested):
```js
class DatasourceEditor extends PureComponent {
constructor() {
this.abortController = new AbortController();
}
async onQueryFormat() {
try {
const response = await this.props.formatQuery(datasource.sql, {
signal: this.abortController.signal
});
this.onDatasourcePropChange('sql', response.json.result);
this.props.addSuccessToast(t('SQL was formatted'));
} catch (error) {
if (error.name === 'AbortError') return; // Request cancelled
// ... handle other errors
}
}
componentWillUnmount() {
this.abortController.abort(); // Cancel all requests
Mousetrap.unbind('ctrl+shift+f');
this.props.resetQuery();
}
}
```
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: [email protected]
For queries about this service, please contact Infrastructure at:
[email protected]
---------------------------------------------------------------------
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]