The Open Standard for Generative UI
fix: skip invalid chart geometry (#986)
Visharad Kashyap664bfe54997f
diff --git a/packages/react-ui/src/components/Charts/shared/LineInBarShape/LineInBarShape.test.tsx b/packages/react-ui/src/components/Charts/shared/LineInBarShape/LineInBarShape.test.tsxnew file mode 100644index 000000000..2bc4d36be--- /dev/null+++ b/packages/react-ui/src/components/Charts/shared/LineInBarShape/LineInBarShape.test.tsx@@ -0,0 +1,32 @@+import { renderToStaticMarkup } from "react-dom/server";+import { describe, expect, it } from "vitest";+import { LineInBarShape } from "./LineInBarShape";++const validGeometry = {+ x: 10,+ y: 20,+ width: 100,+ height: 24,+ orientation: "horizontal" as const,+};++describe("LineInBarShape", () => {+ it("renders finite SVG geometry", () => {+ const markup = renderToStaticMarkup(<LineInBarShape {...validGeometry} />);++ expect(markup).toContain("<path");+ expect(markup).toContain("<line");+ expect(markup).not.toContain("NaN");+ });++ it.each(["x", "y", "width", "height"] as const)(+ "skips rendering when %s is not finite",+ (dimension) => {+ const markup = renderToStaticMarkup(+ <LineInBarShape {...validGeometry} {...{ [dimension]: Number.NaN }} />,+ );++ expect(markup).toBe("");+ },+ );+});diff --git a/packages/react-ui/src/components/Charts/shared/LineInBarShape/LineInBarShape.tsx b/packages/react-ui/src/components/Charts/shared/LineInBarShape/LineInBarShape.tsxindex a55b9e94a..d2c585c67 100644--- a/packages/react-ui/src/components/Charts/shared/LineInBarShape/LineInBarShape.tsx+++ b/packages/react-ui/src/components/Charts/shared/LineInBarShape/LineInBarShape.tsx@@ -327,6 +327,27 @@ const LineInBarShape: FunctionComponent<LineInBarShapeProps> = React.memo((props};}, [x, y, adjustedX, adjustedY, width, height, adjustedWidth, adjustedHeight, isVertical]);+ const hasFiniteGeometry = [+ x,+ y,+ width,+ height,+ adjustedX,+ adjustedY,+ adjustedWidth,+ adjustedHeight,+ rTL,+ rTR,+ rBL,+ rBR,+ ].every(Number.isFinite);++ // Recharts can briefly provide NaN dimensions while a responsive chart is+ // being measured (for example, inside an inactive tab). Rendering those+ // values produces invalid SVG coordinates and React warnings. The chart will+ // render normally once Recharts supplies valid geometry on a later pass.+ if (!hasFiniteGeometry) return null;+return (<g><path d={path} fill={fill} stroke={stroke} strokeWidth={strokeWidth} opacity={opacity} />