Copilot commented on code in PR #35691:
URL: https://github.com/apache/superset/pull/35691#discussion_r2445645077
##########
superset-frontend/src/components/Datasource/components/DatasourceEditor/components/DatasetUsageTab/index.tsx:
##########
@@ -145,7 +148,21 @@ const DatasetUsageTab = ({
behavior: 'smooth',
});
}
- }, 100);
+ });
+ }
+ prevLoadingRef.current = loading;
+
+ // Cleanup: cancel animation frame if component unmounts
+ return () => {
+ if (frameId !== undefined) {
+ cancelAnimationFrame(frameId);
+ }
+ };
Review Comment:
The cleanup function will cancel the animation frame even when it hasn't
been scheduled. The frameId is set inside the conditional block (line 140-151),
but the cleanup runs on every effect execution. This means on initial mount
(when prevLoadingRef.current is false), frameId will be undefined, but the
cleanup will still attempt to cancel it unnecessarily. While not harmful due to
the undefined check, this could be optimized by only returning the cleanup
function when frameId is actually set.
```suggestion
if (frameId !== undefined) {
return () => {
cancelAnimationFrame(frameId);
};
}
```
--
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]