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.

perf(frontend): load the dashboard logic only when a dashboard is used (#125936)

Paul D'Ambra031107c0fe50
diff --git a/frontend/bin/check-eager-graph.mjs b/frontend/bin/check-eager-graph.mjs
index 1247539e0e8f..87cb3180dd97 100644
--- a/frontend/bin/check-eager-graph.mjs
+++ b/frontend/bin/check-eager-graph.mjs
@@ -102,8 +102,8 @@ const ROOTS = [
{
root: AUTHENTICATED_SHELL,
label: 'authenticated shell (every logged-in page)',
- // 2026-10-29: 7.41 MiB eager output, stable CSS included. ~0.5% headroom.
- budgetBytes: 7_810_000,
+ // 2026-10-29: 7.08 MiB eager output, stable CSS included. ~0.3% headroom.
+ budgetBytes: 7_450_000,
forbidden: [
'node_modules/monaco-editor/',
'src/lib/components/ActivityLog/describers',
@@ -166,7 +166,7 @@ const ROOTS = [
'src/scenes/project-homepage/today/TodayHome.tsx',
],
label: 'today home path',
- budgetBytes: 8_115_000,
+ budgetBytes: 7_700_000,
forbidden: [
'src/scenes/project-homepage/ai-first/AiFirstHomepage.tsx',
'src/scenes/project-homepage/today/TodayReportPage.tsx',
@@ -183,8 +183,8 @@ const ROOTS = [
'src/scenes/project-homepage/ai-first/AiFirstHomepage.tsx',
],
label: 'AI-first home path',
- // 2026-10-23: 7.53 MiB (2616 files), stable CSS included. ~5% headroom.
- budgetBytes: 8_290_000,
+ // 2026-10-29: 7.51 MiB, stable CSS included. ~1% headroom.
+ budgetBytes: 7_950_000,
forbidden: [
'products/posthog_ai/frontend/components/tool/widgets/VisualizationWidget.tsx',
'products/posthog_ai/frontend/components/tool/widgets/RecordingsWidget.tsx',
diff --git a/frontend/src/scenes/insights/insightLogic.tsx b/frontend/src/scenes/insights/insightLogic.tsx
index 588505ce01fd..ca36f0372108 100644
--- a/frontend/src/scenes/insights/insightLogic.tsx
+++ b/frontend/src/scenes/insights/insightLogic.tsx
@@ -33,7 +33,6 @@ import { objectsEqual } from 'lib/utils/objects'
import { RetainedValues } from 'lib/utils/retainedValues'
import { withBackLink } from 'scenes/analytics/analyticsBackLink'
import { isDashboardFilterOverrideEmpty } from 'scenes/dashboard/dashboardFilterEmpty'
-import { DashboardLoadAction, dashboardLogic } from 'scenes/dashboard/dashboardLogic'
import { liveDashboardIds } from 'scenes/dashboard/liveDashboardIds'
import { insightSceneLogic } from 'scenes/insights/insightSceneLogic'
import { keyForInsightLogicProps } from 'scenes/insights/sharedUtils'
@@ -1279,11 +1278,15 @@ export const insightLogic: LogicWrapper<insightLogicType> = kea<insightLogicType
// reload dashboards with updated insight
// since filters on dashboard might be different from filters on insight
// we need to trigger dashboard reload to pick up results for updated insight
- savedInsight.dashboard_tiles?.forEach(({ dashboard_id }) =>
- dashboardLogic
- .findMounted({ id: dashboard_id })
- ?.actions.loadDashboard({ action: DashboardLoadAction.Update })
- )
+ if (savedInsight.dashboard_tiles?.length) {
+ // No dashboard logic can be mounted before its module loads, so a failed load has nothing to reload.
+ const dashboardModule = await import('scenes/dashboard/dashboardLogic').catch(() => null)
+ savedInsight.dashboard_tiles.forEach(({ dashboard_id }) =>
+ dashboardModule?.dashboardLogic
+ .findMounted({ id: dashboard_id })
+ ?.actions.loadDashboard({ action: dashboardModule.DashboardLoadAction.Update })
+ )
+ }
if (redirectToViewMode) {
if (!insightNumericId && dashboards?.length === 1) {
diff --git a/frontend/src/scenes/insights/insightSceneLogic.test.ts b/frontend/src/scenes/insights/insightSceneLogic.test.ts
index 74a2bab16c28..de864f5bc6a7 100644
--- a/frontend/src/scenes/insights/insightSceneLogic.test.ts
+++ b/frontend/src/scenes/insights/insightSceneLogic.test.ts
@@ -15,13 +15,14 @@ import { urls } from 'scenes/urls'
import { useMocks } from '~/mocks/jest'
import { cohortsModel } from '~/models/cohortsModel'
+import { dashboardsModel } from '~/models/dashboardsModel'
import { examples } from '~/queries/examples'
import { dataNodeLogic } from '~/queries/nodes/DataNode/dataNodeLogic'
import { insightVizDataNodeKey } from '~/queries/nodes/InsightViz/insightVizKeys'
import { DashboardFilter, HogQLVariable, InsightVizNode, NodeKind, ProductKey } from '~/queries/schema/schema-general'
import { setLatestVersionsOnQuery } from '~/queries/utils'
import { initKeaTests } from '~/test/init'
-import { ActivityScope, CohortType, InsightShortId, InsightType, ItemMode } from '~/types'
+import { ActivityScope, CohortType, DashboardType, InsightShortId, InsightType, ItemMode } from '~/types'
const Insight12 = '12' as InsightShortId
const Insight42 = '42' as InsightShortId
@@ -135,6 +136,17 @@ describe('insightSceneLogic', () => {
expect(logic.values.breadcrumbs.at(-1)?.name).not.toContain('ID 987')
})
+ it('names the breadcrumb after the dashboard the insight opens from', async () => {
+ dashboardsModel.mount()
+ dashboardsModel.actions.addDashboardSuccess({ id: 7, name: 'Weekly review' } as DashboardType)
+ router.actions.push(urls.insightNew(), { dashboard: 7 })
+ logic = insightSceneLogic()
+ logic.mount()
+ await expectLogic(logic).toFinishAllListeners()
+
+ expect(logic.values.dashboardName).toEqual('Weekly review')
+ })
+
it('reports a view only for the scene insight when another unsaved insight mounts', async () => {
const capture = jest.spyOn(posthog, 'capture')
router.actions.push(urls.insightNew())
diff --git a/frontend/src/scenes/insights/insightSceneLogic.tsx b/frontend/src/scenes/insights/insightSceneLogic.tsx
index 645ea7840f21..583015e2869f 100644
--- a/frontend/src/scenes/insights/insightSceneLogic.tsx
+++ b/frontend/src/scenes/insights/insightSceneLogic.tsx
@@ -22,7 +22,6 @@ import { InsightEventSource, sanitizeQuery } from 'lib/utils/eventUsageLogic'
import { isEmptyObject, isObject } from 'lib/utils/guards'
import { analyticsBackLink } from 'scenes/analytics/analyticsBackLink'
import { isDashboardFilterOverrideEmpty } from 'scenes/dashboard/dashboardFilterEmpty'
-import { dashboardLogic } from 'scenes/dashboard/dashboardLogic'
import {
SEARCH_PARAM_FILTERS_KEY,
dashboardSearchParamsFromOverrides,
@@ -41,6 +40,7 @@ import { urls } from 'scenes/urls'
import { sidePanelStateLogic } from '~/layout/navigation-3000/sidepanel/sidePanelStateLogic'
import { SIDE_PANEL_CONTEXT_KEY, SidePanelSceneContext } from '~/layout/navigation-3000/sidepanel/types'
import { sceneLayoutLogic } from '~/layout/scenes/sceneLayoutLogic'
+import { dashboardsModel } from '~/models/dashboardsModel'
import { getDefaultQuery } from '~/queries/nodes/InsightViz/utils'
import {
DashboardFilter,
@@ -915,7 +915,9 @@ export const insightSceneLogic = kea<insightSceneLogicType>([
return
}
- const dashboardName = dashboardLogic.findMounted({ id: dashboard })?.values.dashboard?.name
+ const dashboardName = dashboard
+ ? dashboardsModel.findMounted()?.values.rawDashboards[dashboard]?.name
+ : undefined
const filtersOverride = searchParams['filters_override']
const variablesOverride = searchParams['variables_override']
const tileFiltersOverride = searchParams['tile_filters_override']
diff --git a/frontend/src/scenes/max/maxContextLogic.ts b/frontend/src/scenes/max/maxContextLogic.ts
index d40f2b4d462e..cf966c6cfa39 100644
--- a/frontend/src/scenes/max/maxContextLogic.ts
+++ b/frontend/src/scenes/max/maxContextLogic.ts
@@ -7,8 +7,9 @@ import posthog from 'posthog-js'
import { IconBug, IconCheckbox, IconDashboard, IconGraph, IconNotebook } from '@posthog/icons'
import { TaxonomicFilterGroupType } from 'lib/components/TaxonomicFilter/types'
+import { lemonToast } from 'lib/lemon-ui/LemonToast/LemonToast'
import { objectsEqual } from 'lib/utils/objects'
-import { DashboardLoadAction, RefreshStatus, dashboardLogic } from 'scenes/dashboard/dashboardLogic'
+import type { RefreshStatus } from 'scenes/dashboard/dashboardLogic'
import { insightLogic } from 'scenes/insights/insightLogic'
import { insightSceneLogic } from 'scenes/insights/insightSceneLogic'
import { NotebookListItemType } from 'scenes/notebooks/types'
@@ -497,6 +498,15 @@ export const maxContextLogic = kea<maxContextLogicType>([
let dashboard = data.preloaded
if (!dashboard || !dashboard.tiles) {
+ const dashboardModule = await import('scenes/dashboard/dashboardLogic').catch((error) => {
+ posthog.captureException(error, { feature: 'max_context_dashboard' })
+ lemonToast.error('Could not load the dashboard. Try again.')
+ return null
+ })
+ if (!dashboardModule) {
+ return
+ }
+ const { DashboardLoadAction, dashboardLogic } = dashboardModule
const dashboardLogicInstance = dashboardLogic.build({ id: data.id })
dashboardLogicInstance.mount()