Skip to content

Commit ccb9af4

Browse files
authored
fix(dashboard): restore ResponsiveContainer in ChartContainer (#535)
The dashboard's ChartContainer was missing Recharts' ResponsiveContainer wrapper and the aspect-video CSS class, causing charts to render with no dimensions. The ChartWrapper was using a cloneElement hack to compensate, but this broke after tooltip sync changes. Restore ResponsiveContainer and aspect-video to match the OSS implementation, and remove the now-unnecessary cloneElement workaround.
1 parent 884ad41 commit ccb9af4

2 files changed

Lines changed: 9 additions & 11 deletions

File tree

dashboard/app/project/[id]/dashboard-charts.tsx

Lines changed: 2 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
"use client";
22

3-
import React, { memo, useMemo, cloneElement } from "react";
3+
import React, { memo, useMemo } from "react";
44
import { Loader2 } from "lucide-react";
55
import { Card, CardContent } from "@/components/ui/card";
66
import {
@@ -346,15 +346,9 @@ export const ChartWrapper = memo(function ChartWrapper({
346346
);
347347
}
348348

349-
// Clone the chart element and inject responsive prop and style
350-
const chartWithResponsive = cloneElement(children as React.ReactElement<{ responsive?: boolean; style?: React.CSSProperties }>, {
351-
responsive: true,
352-
style: { width: "100%", height: "100%" },
353-
});
354-
355349
return (
356350
<ChartContainer config={chartConfig} className="h-full w-full">
357-
{chartWithResponsive}
351+
{children}
358352
</ChartContainer>
359353
);
360354
});

dashboard/components/ui/chart.tsx

Lines changed: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -80,7 +80,9 @@ function ChartContainer({
8080
...props
8181
}: React.ComponentProps<"div"> & {
8282
config: ChartConfig
83-
children: React.ReactNode
83+
children: React.ComponentProps<
84+
typeof RechartsPrimitive.ResponsiveContainer
85+
>["children"]
8486
}) {
8587
const uniqueId = React.useId()
8688
const chartId = `chart-${id || uniqueId.replace(/:/g, "")}`
@@ -91,13 +93,15 @@ function ChartContainer({
9193
data-slot="chart"
9294
data-chart={chartId}
9395
className={cn(
94-
"[&_.recharts-cartesian-axis-tick_text]:fill-muted-foreground [&_.recharts-cartesian-grid_line[stroke='#ccc']]:stroke-border/50 [&_.recharts-curve.recharts-tooltip-cursor]:stroke-border [&_.recharts-polar-grid_[stroke='#ccc']]:stroke-border [&_.recharts-radial-bar-background-sector]:fill-muted [&_.recharts-rectangle.recharts-tooltip-cursor]:fill-muted [&_.recharts-reference-line_[stroke='#ccc']]:stroke-border flex justify-center text-xs [&_.recharts-dot[stroke='#fff']]:stroke-transparent [&_.recharts-layer]:outline-hidden [&_.recharts-sector]:outline-hidden [&_.recharts-sector[stroke='#fff']]:stroke-transparent [&_.recharts-surface]:outline-hidden",
96+
"[&_.recharts-cartesian-axis-tick_text]:fill-muted-foreground [&_.recharts-cartesian-grid_line[stroke='#ccc']]:stroke-border/50 [&_.recharts-curve.recharts-tooltip-cursor]:stroke-border [&_.recharts-polar-grid_[stroke='#ccc']]:stroke-border [&_.recharts-radial-bar-background-sector]:fill-muted [&_.recharts-rectangle.recharts-tooltip-cursor]:fill-muted [&_.recharts-reference-line_[stroke='#ccc']]:stroke-border flex aspect-video justify-center text-xs [&_.recharts-dot[stroke='#fff']]:stroke-transparent [&_.recharts-layer]:outline-hidden [&_.recharts-sector]:outline-hidden [&_.recharts-sector[stroke='#fff']]:stroke-transparent [&_.recharts-surface]:outline-hidden",
9597
className
9698
)}
9799
{...props}
98100
>
99101
<ChartStyle id={chartId} config={config} />
100-
{children}
102+
<RechartsPrimitive.ResponsiveContainer>
103+
{children}
104+
</RechartsPrimitive.ResponsiveContainer>
101105
</div>
102106
</ChartContext.Provider>
103107
)

0 commit comments

Comments
 (0)