:hedgehog: PostHog is the leading platform for building self-driving products. Our developer tools – AI observability, analytics, session replay, flags, experiments, error tracking, logs, and more – capture all the context agents need to diagnose problems, uncover opportunities, and ship fixes. Steer it all from Slack, web, desktop, or the MCP.
Python ab-testingai-analyticsanalyticscdpdata-warehouseexperimentsfeature-flagsjavascriptproduct-analyticspythonreactsession-replaysurveystypescriptweb-analytics
fix(quill-charts): pass onError through slope, sparkline and metric card (#123099)
Sam Penningtonbd107e11f430
diff --git a/packages/quill/packages/charts/src/charts/SlopeChart/SlopeChart.test.tsx b/packages/quill/packages/charts/src/charts/SlopeChart/SlopeChart.test.tsxindex 2dfb48539ef1..0071be0cd499 100644--- a/packages/quill/packages/charts/src/charts/SlopeChart/SlopeChart.test.tsx+++ b/packages/quill/packages/charts/src/charts/SlopeChart/SlopeChart.test.tsx@@ -1,7 +1,7 @@-import { fireEvent } from '@testing-library/react'+import { fireEvent, render } from '@testing-library/react'import type { ChartTheme, Series, TooltipContext } from '../../core/types'-import { getChart, renderChart } from '../../testing'+import { ensureJsdom, getChart, renderChart } from '../../testing'import { sortSlopeTooltipRows, type SlopeSeriesMeta } from './slope-data'import { SlopeChart } from './SlopeChart'@@ -336,4 +336,27 @@ describe('SlopeChart', () => {)expect(chart.element.getAttribute('data-attr')).toBe('slope-instance')})++ describe('errors', () => {+ beforeEach(() => {+ jest.spyOn(console, 'error').mockImplementation(() => {})+ })+ afterEach(() => {+ jest.mocked(console.error).mockRestore()+ })++ it('reports an error from its inner chart through onError', () => {+ // Only the base `Chart` reads `axisColor`, so the error starts inside the inner chart's own boundary.+ const theme = {+ ...THEME,+ get axisColor(): string {+ throw new Error('boom')+ },+ } as ChartTheme+ const onError = jest.fn()+ ensureJsdom()+ render(<SlopeChart series={SERIES} labels={LABELS} theme={theme} onError={onError} />)+ expect(onError).toHaveBeenCalledWith(expect.objectContaining({ message: 'boom' }), expect.anything())+ })+ })})diff --git a/packages/quill/packages/charts/src/charts/SlopeChart/SlopeChart.tsx b/packages/quill/packages/charts/src/charts/SlopeChart/SlopeChart.tsxindex ec169ab2fb74..157487319c45 100644--- a/packages/quill/packages/charts/src/charts/SlopeChart/SlopeChart.tsx+++ b/packages/quill/packages/charts/src/charts/SlopeChart/SlopeChart.tsx@@ -76,10 +76,10 @@ export interface SlopeChartProps<Meta = SlopeSeriesMeta> {onError?: (error: Error, info: React.ErrorInfo) => void}-export function SlopeChart<Meta = SlopeSeriesMeta>({ onError, ...rest }: SlopeChartProps<Meta>): React.ReactElement {+export function SlopeChart<Meta = SlopeSeriesMeta>(props: SlopeChartProps<Meta>): React.ReactElement {return (- <ChartErrorBoundary onError={onError}>- <SlopeChartInner {...rest} />+ <ChartErrorBoundary onError={props.onError}>+ <SlopeChartInner {...props} /></ChartErrorBoundary>)}@@ -98,6 +98,7 @@ function SlopeChartInner<Meta = SlopeSeriesMeta>({className,dataAttr,children,+ onError,}: SlopeChartProps<Meta>): React.ReactElement {const {showSeriesLabels = true,@@ -233,6 +234,7 @@ function SlopeChartInner<Meta = SlopeSeriesMeta>({onPointClick={onPointClick}className={className}dataAttr={dataAttr}+ onError={onError}><SlopeValueLabelsvalueFormatter={valueFormatter}diff --git a/packages/quill/packages/charts/src/charts/Sparkline/Sparkline.test.tsx b/packages/quill/packages/charts/src/charts/Sparkline/Sparkline.test.tsxindex 5e89091c9ea0..789a7ea30704 100644--- a/packages/quill/packages/charts/src/charts/Sparkline/Sparkline.test.tsx+++ b/packages/quill/packages/charts/src/charts/Sparkline/Sparkline.test.tsx@@ -1,8 +1,8 @@-import { fireEvent } from '@testing-library/react'+import { fireEvent, render } from '@testing-library/react'import type { ChartTheme, TooltipContext } from '../../core/types'import { DefaultTooltip } from '../../overlays/DefaultTooltip'-import { createDefaultTooltipAccessor, hoverUntilTooltip, renderChart } from '../../testing'+import { createDefaultTooltipAccessor, ensureJsdom, hoverUntilTooltip, renderChart } from '../../testing'import { Sparkline } from './Sparkline'const THEME: ChartTheme = { colors: ['#22d3ee', '#f14f58'], backgroundColor: '#ffffff' }@@ -88,4 +88,27 @@ describe('Sparkline', () => {const tooltip = createDefaultTooltipAccessor(await hoverUntilTooltip(chart.element, 2, LABELS.length))expect(tooltip.label()).toBe('Mar')})++ describe('errors', () => {+ beforeEach(() => {+ jest.spyOn(console, 'error').mockImplementation(() => {})+ })+ afterEach(() => {+ jest.mocked(console.error).mockRestore()+ })++ it('reports an error from its inner chart through onError', () => {+ // Only the base `Chart` reads `axisColor`, so the error starts inside the inner chart's own boundary.+ const theme = {+ ...THEME,+ get axisColor(): string {+ throw new Error('boom')+ },+ } as ChartTheme+ const onError = jest.fn()+ ensureJsdom()+ render(<Sparkline data={[1, 2, 3]} theme={theme} onError={onError} />)+ expect(onError).toHaveBeenCalledWith(expect.objectContaining({ message: 'boom' }), expect.anything())+ })+ })})diff --git a/packages/quill/packages/charts/src/charts/Sparkline/Sparkline.tsx b/packages/quill/packages/charts/src/charts/Sparkline/Sparkline.tsxindex 344be4743713..3684c1e1c852 100644--- a/packages/quill/packages/charts/src/charts/Sparkline/Sparkline.tsx+++ b/packages/quill/packages/charts/src/charts/Sparkline/Sparkline.tsx@@ -56,10 +56,9 @@ const LINE_MARGINS = { top: 6, right: 0, bottom: 6, left: 0 }const BAR_MARGINS = { top: 2, right: 0, bottom: 0, left: 0 }export function Sparkline(props: SparklineProps): React.ReactElement {- const { onError, ...rest } = propsreturn (- <ChartErrorBoundary onError={onError}>- <SparklineInner {...rest} />+ <ChartErrorBoundary onError={props.onError}>+ <SparklineInner {...props} /></ChartErrorBoundary>)}@@ -80,7 +79,8 @@ function SparklineInner({tooltip,className,dataAttr,-}: Omit<SparklineProps, 'onError'>): React.ReactElement {+ onError,+}: SparklineProps): React.ReactElement {const resolvedColor = color ?? theme.colors[0]const chartSeries = useMemo<Series[]>(() => {if (series) {@@ -129,11 +129,25 @@ function SparklineInner({data-attr={dataAttr}>{type === 'bar' ? (- <BarChart series={chartSeries} labels={resolvedLabels} theme={theme} config={config} tooltip={tooltip}>+ <BarChart+ series={chartSeries}+ labels={resolvedLabels}+ theme={theme}+ config={config}+ tooltip={tooltip}+ onError={onError}+ >{watcher}</BarChart>) : (- <LineChart series={chartSeries} labels={resolvedLabels} theme={theme} config={config} tooltip={tooltip}>+ <LineChart+ series={chartSeries}+ labels={resolvedLabels}+ theme={theme}+ config={config}+ tooltip={tooltip}+ onError={onError}+ >{watcher}</LineChart>)}diff --git a/packages/quill/packages/charts/src/components/MetricCard/MetricCard.test.tsx b/packages/quill/packages/charts/src/components/MetricCard/MetricCard.test.tsxindex 08e0e11f8c75..7a4e97794914 100644--- a/packages/quill/packages/charts/src/components/MetricCard/MetricCard.test.tsx+++ b/packages/quill/packages/charts/src/components/MetricCard/MetricCard.test.tsx@@ -441,4 +441,26 @@ describe('MetricCard', () => {expect(valueOnly.container.querySelector('[data-attr="metric-card-subtitle"]')).toBeNull()})})++ describe('errors', () => {+ beforeEach(() => {+ jest.spyOn(console, 'error').mockImplementation(() => {})+ })+ afterEach(() => {+ jest.mocked(console.error).mockRestore()+ })++ it('reports an error from its inner chart through onError', () => {+ // Only the base `Chart` reads `axisColor`, so the error starts inside the inner chart's own boundary.+ const theme = {+ ...THEME,+ get axisColor(): string {+ throw new Error('boom')+ },+ } as ChartTheme+ const onError = jest.fn()+ render(<MetricCard title="Visits" data={[1, 2, 3]} theme={theme} onError={onError} />)+ expect(onError).toHaveBeenCalledWith(expect.objectContaining({ message: 'boom' }), expect.anything())+ })+ })})diff --git a/packages/quill/packages/charts/src/components/MetricCard/MetricCard.tsx b/packages/quill/packages/charts/src/components/MetricCard/MetricCard.tsxindex c7a1789027f4..36d308ff7878 100644--- a/packages/quill/packages/charts/src/components/MetricCard/MetricCard.tsx+++ b/packages/quill/packages/charts/src/components/MetricCard/MetricCard.tsx@@ -81,10 +81,9 @@ export interface MetricCardProps {}export function MetricCard(props: MetricCardProps): React.ReactElement | null {- const { onError, ...rest } = propsreturn (- <ChartErrorBoundary onError={onError}>- <MetricCardInner {...rest} />+ <ChartErrorBoundary onError={props.onError}>+ <MetricCardInner {...props} /></ChartErrorBoundary>)}@@ -120,7 +119,8 @@ function MetricCardInner({hoverIntentMs = 60,className,dataAttr,-}: Omit<MetricCardProps, 'onError'>): React.ReactElement | null {+ onError,+}: MetricCardProps): React.ReactElement | null {const sparklineData = data != null && data.length > 0 && theme != null ? data : nullconst lastIndex = sparklineData ? sparklineData.length - 1 : -1@@ -228,6 +228,7 @@ function MetricCardInner({onHoverIndexChange={setHoverIndex}className={sparklineClassName}dataAttr="metric-card-sparkline"+ onError={onError}/>)}</div>