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): show a load error instead of an empty state (#87473)

posthog[bot]99323e62bfd8
diff --git a/frontend/snapshots.yml b/frontend/snapshots.yml
index e30471330ad1..68a54377e841 100644
--- a/frontend/snapshots.yml
+++ b/frontend/snapshots.yml
@@ -8096,6 +8096,10 @@ snapshots:
hash: v1.k794b7964.43545664c9133c8afd354be6a6ed8f808c35b381101325d9605114632fcdc0c9.l8w9uEOEmrH6Xl1kNd9ueRtg_51cJUSjWLdjWDM0Fko
scenes-app-saved-insights--empty-state--light:
hash: v1.k794b7964.51af80cf2b3eecf0b3b5265d0436d838e0005c3eaaf6c3d6864fe39b95395c99.X5NeESdMpZsVx89cw3gJIhyFSwfiWqeJc8iiTdBlif8
+ scenes-app-saved-insights--error-state--dark:
+ hash: v1.k794b7964.e36c42a3d00537e266ce0f36ed697e8725d21d659bf6f0474effac61ec9e9ab7.NK9LPesw67E4MoiSNayIfQK-Pq9AGmFBAGMMZfTDq3M
+ scenes-app-saved-insights--error-state--light:
+ hash: v1.k794b7964.be46188af42c8c13e3f85dc5bdddedfe6d03860b4dc60d7fe50271f63791540e.WW0hRR8a1JnTW_-QEgfYc7kcJXrCVI4fKKAGYgn0lxo
scenes-app-saved-insights--list-view--dark:
hash: v1.k794b7964.1a5aa80f818d3ef28c13fcfa5f31e1fb63d06e0f1e41784b6106c46baea27a4e.qmZSyrTsDuLr2Y8FF97SwzbzcqSneHIan3-gsQ9EXhk
scenes-app-saved-insights--list-view--light:
diff --git a/frontend/src/scenes/insights/EmptyStates/EmptyStates.tsx b/frontend/src/scenes/insights/EmptyStates/EmptyStates.tsx
index beb398f7ffbb..268a210d4d3f 100644
--- a/frontend/src/scenes/insights/EmptyStates/EmptyStates.tsx
+++ b/frontend/src/scenes/insights/EmptyStates/EmptyStates.tsx
@@ -1094,6 +1094,25 @@ const SAVED_INSIGHTS_COPY = {
},
}
+export function SavedInsightsErrorState({ onRetry }: { onRetry: () => void }): JSX.Element {
+ return (
+ <div
+ data-attr="saved-insights-error-state"
+ className="flex flex-col items-center justify-center gap-2 text-center"
+ >
+ <IconErrorOutline className="text-4xl shrink-0 text-danger" />
+ <h2 className="mb-0">Couldn't load insights</h2>
+ <p className="empty-state__description">
+ Something went wrong loading your insights. They are safe. Try again, and if the problem continues
+ contact support.
+ </p>
+ <LemonButton type="primary" size="small" icon={<IconRefresh />} onClick={onRetry}>
+ Try again
+ </LemonButton>
+ </div>
+ )
+}
+
export function SavedInsightsEmptyState({
filters,
usingFilters,
diff --git a/frontend/src/scenes/saved-insights/SavedInsights.stories.tsx b/frontend/src/scenes/saved-insights/SavedInsights.stories.tsx
index 3b744e5ed761..178fe10b94e1 100644
--- a/frontend/src/scenes/saved-insights/SavedInsights.stories.tsx
+++ b/frontend/src/scenes/saved-insights/SavedInsights.stories.tsx
@@ -53,6 +53,16 @@ export const EmptyState: Story = {
],
}
+export const ErrorState: Story = {
+ decorators: [
+ mswDecorator({
+ get: {
+ '/api/environments/:team_id/insights': () => [500, { detail: 'Internal server error' }],
+ },
+ }),
+ ],
+}
+
export const SearchResults: Story = {
parameters: {
pageUrl: urls.savedInsights() + '?search=revenue',
diff --git a/frontend/src/scenes/saved-insights/SavedInsights.tsx b/frontend/src/scenes/saved-insights/SavedInsights.tsx
index e5079726cb45..0db4e5197478 100644
--- a/frontend/src/scenes/saved-insights/SavedInsights.tsx
+++ b/frontend/src/scenes/saved-insights/SavedInsights.tsx
@@ -26,7 +26,7 @@ import { accessLevelSatisfied } from 'lib/utils/accessControlUtils'
import { cn } from 'lib/utils/css-classes'
import { deleteInsightWithUndo } from 'lib/utils/deleteWithUndo'
import { isNonEmptyObject } from 'lib/utils/guards'
-import { SavedInsightsEmptyState } from 'scenes/insights/EmptyStates'
+import { SavedInsightsEmptyState, SavedInsightsErrorState } from 'scenes/insights/EmptyStates'
import { useSummarizeInsight } from 'scenes/insights/summarizeInsight'
import { projectLogic } from 'scenes/projectLogic'
import { NewInsightShortcuts } from 'scenes/saved-insights/newInsightsMenu'
@@ -95,6 +95,7 @@ export function SavedInsights(): JSX.Element {
const {
insights,
insightsLoading,
+ insightsLoadFailed,
filters,
sorting,
pagination,
@@ -379,7 +380,11 @@ export function SavedInsights(): JSX.Element {
<LemonTable
loading={insightsLoading}
columns={columns}
- dataSource={draftInsightRow ? [draftInsightRow, ...insights.results] : insights.results}
+ dataSource={
+ draftInsightRow && !(insightsLoadFailed && insights.results.length < 1)
+ ? [draftInsightRow, ...insights.results]
+ : insights.results
+ }
rowClassName={(record) => (isDraftInsightRow(record) ? 'bg-warning-highlight' : null)}
pagination={pagination}
noSortingCancellation
@@ -396,7 +401,11 @@ export function SavedInsights(): JSX.Element {
nouns={['insight', 'insights']}
hideSortingIndicatorWhenInactive
emptyState={
- !insightsLoading && insights.count < 1 ? (
+ !insightsLoading && insightsLoadFailed && insights.results.length < 1 ? (
+ <div className="py-8">
+ <SavedInsightsErrorState onRetry={() => loadInsights(false)} />
+ </div>
+ ) : !insightsLoading && insights.count < 1 ? (
<div className="py-8">
<SavedInsightsEmptyState filters={filters} usingFilters={usingFilters} />
</div>
diff --git a/frontend/src/scenes/saved-insights/savedInsightsLogic.test.ts b/frontend/src/scenes/saved-insights/savedInsightsLogic.test.ts
index 9dd4f69ace44..6adbce3e4cb3 100644
--- a/frontend/src/scenes/saved-insights/savedInsightsLogic.test.ts
+++ b/frontend/src/scenes/saved-insights/savedInsightsLogic.test.ts
@@ -255,6 +255,30 @@ describe('savedInsightsLogic', () => {
)
})
+ it('flags a failed load so the list can show an error instead of an empty state', async () => {
+ useMocks({
+ get: {
+ '/api/environments/:team_id/insights/': () => [500, { detail: 'boom' }],
+ },
+ })
+
+ logic.actions.loadInsights(false)
+ await expectLogic(logic)
+ .toDispatchActions(['loadInsights', 'loadInsightsFailure'])
+ .toMatchValues({ insightsLoadFailed: true })
+
+ // A later successful load clears the flag so a recovered list drops the error state
+ useMocks({
+ get: {
+ '/api/environments/:team_id/insights/': () => [200, createSavedInsights('recovered', 0)],
+ },
+ })
+ logic.actions.loadInsights(false)
+ await expectLogic(logic)
+ .toDispatchActions(['loadInsights', 'loadInsightsSuccess'])
+ .toMatchValues({ insightsLoadFailed: false })
+ })
+
it('discards stale API responses when a newer request is in flight', async () => {
const pendingRequests: Array<{
resolve: (value: [number, any]) => void
diff --git a/frontend/src/scenes/saved-insights/savedInsightsLogic.ts b/frontend/src/scenes/saved-insights/savedInsightsLogic.ts
index 5a63b99c89e6..2f3defdcdebe 100644
--- a/frontend/src/scenes/saved-insights/savedInsightsLogic.ts
+++ b/frontend/src/scenes/saved-insights/savedInsightsLogic.ts
@@ -162,6 +162,7 @@ export interface savedInsightsLogicValues {
draftQuery: DraftInsightQuery | null
filters: SavedInsightFilters
insights: InsightsResult
+ insightsLoadFailed: boolean
insightsLoading: boolean
pagination: PaginationManual
paramsFromFilters: Record<string, any>
@@ -482,6 +483,14 @@ export const savedInsightsLogic = kea<savedInsightsLogicType>([
}),
},
],
+ insightsLoadFailed: [
+ false,
+ {
+ loadInsights: () => false,
+ loadInsightsSuccess: () => false,
+ loadInsightsFailure: () => true,
+ },
+ ],
dashboardUpdatesInProgress: [
{} as Record<number, boolean>,
{