bito-code-review[bot] commented on code in PR #37501:
URL: https://github.com/apache/superset/pull/37501#discussion_r2748578198
##########
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;
- }>({});
- const onResize = useCallback(() => {
- if (ref.current) {
- const { width, height } = ref.current.getBoundingClientRect?.() || {};
- setChartPanelSize({ width, height });
- }
- }, []);
- const { ref: observerRef } = useResizeDetector({
+ const {
+ width: rawWidth,
+ height: rawHeight,
+ ref,
+ } = useResizeDetector({
refreshMode: 'debounce',
- refreshRate: 300,
- onResize,
+ refreshRate: 250,
+ handleHeight: true,
+ handleWidth: true,
+ skipOnMount: true,
});
Review Comment:
<div>
<div id="suggestion">
<div id="issue"><b>Broken initial chart render</b></div>
<div id="fix">
Setting skipOnMount to true skips the initial resize event, leaving width
and height undefined until the first resize. This prevents ChartContainer from
rendering initially in `ExploreChartPanel`, as it only renders when both
dimensions are defined.
</div>
<details>
<summary>
<b>Code suggestion</b>
</summary>
<blockquote>Check the AI-generated fix before applying</blockquote>
<div id="code">
````suggestion
refreshMode: 'debounce',
refreshRate: 250,
handleHeight: true,
handleWidth: true,
skipOnMount: false,
});
````
</div>
</details>
</div>
<small><i>Code Review Run #988724</i></small>
</div>
---
Should Bito avoid suggestions like this for future reviews? (<a
href=https://alpha.bito.ai/home/ai-agents/review-rules>Manage Rules</a>)
- [ ] Yes, avoid them
--
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]