ramiroaquinoromero commented on code in PR #37501:
URL: https://github.com/apache/superset/pull/37501#discussion_r2744340303
##########
superset-frontend/src/explore/components/ExploreChartPanel/useResizeDetectorByObserver.ts:
##########
@@ -16,30 +16,35 @@
* specific language governing permissions and limitations
* under the License.
*/
-import { useState, useCallback, useRef } from 'react';
+import { useMemo } from 'react';
import { useResizeDetector } from 'react-resize-detector';
export default function useResizeDetectorByObserver() {
- const ref = useRef<HTMLDivElement>(null);
- const [{ width, height }, setChartPanelSize] = useState<{
- width?: number;
- height?: number;
- }>({});
Review Comment:
I checked the codebase and useResizeDetectorByObserver is only used in
ExploreChartPanel/index.tsx. The hook is specifically designed for this
component's needs.
The changes simplify the implementation by:
- Removing internal state management that was causing unnecessary re-renders
- Leveraging react-resize-detector's built-in debouncing (refreshMode:
'debounce', refreshRate: 100)
- Using useMemo to floor dimensions and prevent sub-pixel render loops
- Since it's only used in one place, there are no side effects on other
components
##########
superset-frontend/src/explore/components/ExploreChartPanel/index.tsx:
##########
@@ -243,19 +262,23 @@ const ExploreChartPanel = ({
setShowSplit(isOpen);
}, []);
- const renderChart = useCallback(
+ const renderChart = useMemo(
Review Comment:
This optimizes chart loading by preventing the graph from recalculating if
it hasn't changed. Since it directly returns JSX, useMemo is fully compatible
and avoids unnecessary re-renders
--
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]