Skip to content

Commit 7c681b5

Browse files
committed
Fix for Rendered more hooks than during the previous render.
1 parent 947b750 commit 7c681b5

File tree

1 file changed

+14
-13
lines changed

1 file changed

+14
-13
lines changed

apps/webapp/app/components/code/QueryResultsChart.tsx

Lines changed: 14 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -791,6 +791,20 @@ export const QueryResultsChart = memo(function QueryResultsChart({
791791
};
792792
}, [isDateBased, timeGranularity]);
793793

794+
// Y-axis domain calculation - must be before early returns to maintain consistent hook order
795+
const yAxisDomain = useMemo(() => {
796+
let min = 0;
797+
for (const point of data) {
798+
for (const s of series) {
799+
const val = point[s];
800+
if (typeof val === "number" && isFinite(val)) {
801+
min = Math.min(min, val);
802+
}
803+
}
804+
}
805+
return [min, "auto"] as [number, string];
806+
}, [data, series]);
807+
794808
// Validation
795809
if (!xAxisColumn) {
796810
return <EmptyState message="Select an X-axis column to display the chart" />;
@@ -838,19 +852,6 @@ export const QueryResultsChart = memo(function QueryResultsChart({
838852
// (prevents massive bars when there are only a few data points)
839853
const xAxisPropsForBar = baseXAxisProps;
840854

841-
const yAxisDomain = useMemo(() => {
842-
let min = 0;
843-
for (const point of data) {
844-
for (const s of series) {
845-
const val = point[s];
846-
if (typeof val === "number" && isFinite(val)) {
847-
min = Math.min(min, val);
848-
}
849-
}
850-
}
851-
return [min, "auto"] as [number, string];
852-
}, [data, series]);
853-
854855
const yAxisProps = {
855856
tickFormatter: yAxisFormatter,
856857
domain: yAxisDomain,

0 commit comments

Comments
 (0)