Skip to content

: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.

fix(insights): stop a missing color theme from blanking charts (#92442)

posthog[bot]85721c99381a
diff --git a/frontend/src/lib/colors.ts b/frontend/src/lib/colors.ts
index be6e824002cb..26e2d6df95dd 100644
--- a/frontend/src/lib/colors.ts
+++ b/frontend/src/lib/colors.ts
@@ -48,6 +48,32 @@ export type DataColorTheme = Partial<Record<DataColorToken, string>> & {
[key: `preset-${number}`]: string
}
+const FALLBACK_DATA_COLOR_THEME_COLORS = [
+ '#1d4aff',
+ '#621da6',
+ '#42827e',
+ '#ce0e74',
+ '#f14f58',
+ '#7c440e',
+ '#529a0a',
+ '#0476fb',
+ '#fe729e',
+ '#35416b',
+ '#41cbc4',
+ '#b64b02',
+ '#e4a604',
+ '#a56eff',
+ '#30d5c8',
+] as const
+
+export const FALLBACK_DATA_COLOR_THEME: DataColorTheme = FALLBACK_DATA_COLOR_THEME_COLORS.reduce(
+ (theme, color, index) => {
+ theme[`preset-${index + 1}`] = color
+ return theme
+ },
+ {} as DataColorTheme
+)
+
export function getColorVar(variable: string): string {
const colorValue = getComputedStyle(document.body).getPropertyValue('--' + variable)
if (!colorValue) {
diff --git a/frontend/src/lib/logic/dataThemeLogic.test.ts b/frontend/src/lib/logic/dataThemeLogic.test.ts
new file mode 100644
index 000000000000..92c5db496609
--- /dev/null
+++ b/frontend/src/lib/logic/dataThemeLogic.test.ts
@@ -0,0 +1,52 @@
+import { expectLogic } from 'kea-test-utils'
+
+import api from 'lib/api'
+import { FALLBACK_DATA_COLOR_THEME } from 'lib/colors'
+import { dataThemeLogic } from 'lib/logic/dataThemeLogic'
+
+import { resumeKeaLoadersErrors, silenceKeaLoadersErrors } from '~/initKea'
+import { initKeaTests } from '~/test/init'
+
+describe('dataThemeLogic', () => {
+ let logic: ReturnType<typeof dataThemeLogic.build>
+
+ afterEach(() => {
+ logic?.unmount()
+ delete window.POSTHOG_RENDER_QUERY_PAYLOAD
+ jest.restoreAllMocks()
+ resumeKeaLoadersErrors()
+ })
+
+ it('getTheme falls back to the built-in default when the list resolved but no theme matched', async () => {
+ window.POSTHOG_RENDER_QUERY_PAYLOAD = { themes: [] } as any
+ initKeaTests()
+ logic = dataThemeLogic()
+ logic.mount()
+
+ await expectLogic(logic).toMatchValues({ defaultTheme: null })
+ expect(logic.values.getTheme(undefined)).toEqual(FALLBACK_DATA_COLOR_THEME)
+ expect(logic.values.getTheme(999)).toEqual(FALLBACK_DATA_COLOR_THEME)
+ })
+
+ it('getTheme returns null while the themes list is still loading', async () => {
+ window.POSTHOG_RENDER_QUERY_PAYLOAD = { themes: [] } as any
+ initKeaTests()
+ logic = dataThemeLogic()
+ logic.mount()
+ logic.actions.setThemes(null)
+
+ await expectLogic(logic).toMatchValues({ themes: null })
+ expect(logic.values.getTheme(undefined)).toBeNull()
+ })
+
+ it('getTheme falls back to the built-in default when loading themes fails', async () => {
+ silenceKeaLoadersErrors()
+ jest.spyOn(api.dataColorThemes, 'list').mockRejectedValue(new Error('Unable to load themes'))
+ initKeaTests()
+ logic = dataThemeLogic()
+ logic.mount()
+
+ await expectLogic(logic).toDispatchActions(['loadThemesFailure']).toMatchValues({ themes: [] })
+ expect(logic.values.getTheme(undefined)).toEqual(FALLBACK_DATA_COLOR_THEME)
+ })
+})
diff --git a/frontend/src/lib/logic/dataThemeLogic.tsx b/frontend/src/lib/logic/dataThemeLogic.tsx
index e0b790234beb..6594da8a6b0a 100644
--- a/frontend/src/lib/logic/dataThemeLogic.tsx
+++ b/frontend/src/lib/logic/dataThemeLogic.tsx
@@ -2,7 +2,7 @@ import { MakeLogicType, actions, afterMount, connect, kea, path, props, reducers
import { loaders } from 'kea-loaders'
import api from 'lib/api'
-import { DataColorTheme, DataColorToken } from 'lib/colors'
+import { DataColorTheme, DataColorToken, FALLBACK_DATA_COLOR_THEME } from 'lib/colors'
import { teamLogic } from 'scenes/teamLogic'
import { DataColorThemeModel } from '~/types'
@@ -108,6 +108,7 @@ export const dataThemeLogic = kea<dataThemeLogicType>([
reducers({
themes: {
setThemes: (_, { themes }) => themes,
+ loadThemesFailure: () => [],
},
}),
selectors({
@@ -163,7 +164,7 @@ export const dataThemeLogic = kea<dataThemeLogicType>([
}, {} as DataColorTheme)
}
- return null
+ return themes != null ? FALLBACK_DATA_COLOR_THEME : null
},
],
getColorFromToken: [
diff --git a/frontend/src/queries/nodes/InsightViz/InsightVizDisplay.tsx b/frontend/src/queries/nodes/InsightViz/InsightVizDisplay.tsx
index 50d73f3c012b..6222eb994bd5 100644
--- a/frontend/src/queries/nodes/InsightViz/InsightVizDisplay.tsx
+++ b/frontend/src/queries/nodes/InsightViz/InsightVizDisplay.tsx
@@ -94,7 +94,7 @@ function DashboardInsightRefreshHintOrLoading({
key={queryId}
insightProps={insightProps}
renderEmptyStateAsSkeleton={context?.renderEmptyStateAsSkeleton}
- suppressSlowQuerySuggestions={context?.suppressSlowQuerySuggestions}
+ suppressSlowQuerySuggestions
/>
)
}
@@ -498,7 +498,15 @@ export function InsightVizDisplay({
// Web Analytics insights don't use themes, so allow them to render without waiting for theme to load
if (!theme && activeView !== InsightType.WEB_ANALYTICS) {
- return null
+ return (
+ <InsightLoadingState
+ queryId={queryId}
+ key={queryId}
+ insightProps={insightProps}
+ renderEmptyStateAsSkeleton={context?.renderEmptyStateAsSkeleton}
+ suppressSlowQuerySuggestions={context?.suppressSlowQuerySuggestions}
+ />
+ )
}
return (