: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(insights): guard trends charts against null series data (#86964)
posthog[bot]d9983d1ba13a
diff --git a/packages/quill/packages/charts/src/core/scales.test.ts b/packages/quill/packages/charts/src/core/scales.test.tsindex 4f95cf4325dd..20b439c57a81 100644--- a/packages/quill/packages/charts/src/core/scales.test.ts+++ b/packages/quill/packages/charts/src/core/scales.test.ts@@ -113,6 +113,16 @@ describe('hog-charts scales', () => {expect(scale.domain()).toEqual([0, 1])})+ it('treats a series with null data as empty instead of throwing', () => {+ // A query that returned no points can hand the chart `data: null`, which the `number[]`+ // type forbids but the runtime still sees. Iterating it used to crash the whole chart.+ const nullData = { ...makeSeries({ key: 'empty', data: [] }), data: null as unknown as number[] }+ const withData = makeSeries({ key: 's1', data: [10, 20] })+ const [domainMin, domainMax] = createYScale([withData, nullData], dimensions).domain()+ expect(domainMin).toBe(0)+ expect(domainMax).toBeGreaterThanOrEqual(20)+ })+it('excludes visibility.excluded series from the domain calculation', () => {const visible = makeSeries({ key: 'v', data: [0, 10] })const hidden = makeSeries({ key: 'h', data: [0, 1000], visibility: { excluded: true } })diff --git a/packages/quill/packages/charts/src/core/scales.ts b/packages/quill/packages/charts/src/core/scales.tsindex bf115e2a8331..3e2fd177cc09 100644--- a/packages/quill/packages/charts/src/core/scales.ts+++ b/packages/quill/packages/charts/src/core/scales.ts@@ -52,9 +52,12 @@ export function seriesValueRange(series: Series[]): SeriesValueRange {if (s.visibility?.excluded) {continue}+ // `data` is typed `number[]`, but a series can reach here with a null `data` from a query+ // that returned no points — iterating it directly throws. Treat a missing array as empty.+ const data = s.data ?? []// A confidence ribbon's lower bound (`fill.lowerData`) is part of the data's visible// extent, so it must widen the axis too — otherwise the band clips at the top series.- for (const v of s.fill?.lowerData ? [...s.data, ...s.fill.lowerData] : s.data) {+ for (const v of s.fill?.lowerData ? [...data, ...s.fill.lowerData] : data) {if (v == null || !isFinite(v)) {continue}