: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(dashboards): guard post-await logic reads against unmount (#65610)
posthog[bot]0529c5e4225e
diff --git a/frontend/src/scenes/dashboard/newDashboardLogic.ts b/frontend/src/scenes/dashboard/newDashboardLogic.tsindex 3937248cd968..77a29bca3acd 100644--- a/frontend/src/scenes/dashboard/newDashboardLogic.ts+++ b/frontend/src/scenes/dashboard/newDashboardLogic.ts@@ -194,6 +194,11 @@ export const newDashboardLogic = kea<newDashboardLogicType>([}),submit: async ({ name, description, useTemplate, show, _create_in_folder }, breakpoint) => {actions.setIsLoading(true)+ // Read before the await: the modal/menu that mounts this logic can close+ // mid-request (e.g. the "Start from scratch" menu), unmounting it. Reading+ // `values` afterwards throws `[KEA] Can not find path`, which the catch below+ // would mislabel as "Could not create dashboard" even though creation succeeded.+ const redirectAfterCreation = values.redirectAfterCreationtry {const result: DashboardType = await api.create(`api/environments/${teamLogic.values.currentTeamId}/dashboards/`,@@ -213,7 +218,7 @@ export const newDashboardLogic = kea<newDashboardLogicType>([tryShowMCPHint('dashboards.create', {derivedPrompt: result.name ? `Build a dashboard called ${result.name}` : undefined,})- if (show && values.redirectAfterCreation) {+ if (show && redirectAfterCreation) {breakpoint()router.actions.push(urls.dashboard(result.id))}diff --git a/frontend/src/scenes/insights/insightSceneLogic.tsx b/frontend/src/scenes/insights/insightSceneLogic.tsxindex 942e5a52c3ed..56a91af00040 100644--- a/frontend/src/scenes/insights/insightSceneLogic.tsx+++ b/frontend/src/scenes/insights/insightSceneLogic.tsx@@ -480,18 +480,21 @@ export const insightSceneLogic = kea<insightSceneLogicType>([const alertChanged = (alert_id ?? null) !== values.alertIdconst isExistingInsight = shortId !== 'new'- const itemIdChanged =- (currentScene?.activeSceneLogic as BuiltLogic<insightSceneLogicType>)?.values.itemId !==- normalizeItemId(itemId)+ // `activeSceneLogic` can unmount mid-transition (e.g. navigating dashboard ↔ insight edit).+ // Reading `.values` on an unmounted logic throws `[KEA] Can not find path`, so only read it+ // while it's still mounted — otherwise treat the scene as changed and re-process below.+ const activeSceneLogic = currentScene?.activeSceneLogic as BuiltLogic<insightSceneLogicType> | undefined+ const activeSceneValues = activeSceneLogic?.isMounted() ? activeSceneLogic.values : undefined++ const itemIdChanged = activeSceneValues?.itemId !== normalizeItemId(itemId)if (isExistingInsight &&method !== 'PUSH' &¤tScene?.activeSceneId === Scene.Insight &&- currentScene.activeSceneLogic &&- (currentScene.activeSceneLogic as BuiltLogic<insightSceneLogicType>).values.insightId === insightId &&- (currentScene.activeSceneLogic as BuiltLogic<insightSceneLogicType>).values.insightMode ===- insightMode &&+ activeSceneValues &&+ activeSceneValues.insightId === insightId &&+ activeSceneValues.insightMode === insightMode &&!alertChanged &&!itemIdChanged) {