: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 templates list refresh against unmount (#57941)
Sam Pennington6a17437e9685
diff --git a/frontend/src/scenes/dashboard/dashboardTemplateEditorLogic.ts b/frontend/src/scenes/dashboard/dashboardTemplateEditorLogic.tsindex 082326eb12aa..b282ff5b50be 100644--- a/frontend/src/scenes/dashboard/dashboardTemplateEditorLogic.ts+++ b/frontend/src/scenes/dashboard/dashboardTemplateEditorLogic.ts@@ -14,12 +14,17 @@ import type { dashboardTemplateEditorLogicType } from './dashboardTemplateEditor/*** Refresh every mounted `dashboardTemplatesLogic` slice we use in-product:- * - templates tab: `default-all-templatesTab` (via callback)+ * - templates tab: `default-all-templatesTab`* - new dashboard chooser: `default-all` / `feature_flag-all`* - dashboards page featured row: `default-featured`+ *+ * All four go through `findMounted` so we never dispatch into an unmounted instance.+ * `connect.actions` did not reliably keep the templates-tab logic mounted across the+ * editor/modal lifecycle, which surfaced as `[KEA] Can not find path … in the store.`+ * when the post-save loader read its own reducers.*/-function refreshDashboardTemplateListsAfterMutation(templatesTabListGetAll: () => void): void {- templatesTabListGetAll()+function refreshDashboardTemplateListsAfterMutation(): void {+ dashboardTemplatesLogic.findMounted({ scope: 'default', templatesTabList: true })?.actions.getAllTemplates()dashboardTemplatesLogic.findMounted({ scope: 'default' })?.actions.getAllTemplates()dashboardTemplatesLogic.findMounted({ scope: 'feature_flag' })?.actions.getAllTemplates()dashboardTemplatesLogic@@ -42,7 +47,6 @@ function parseDashboardTemplateEditorPayload(raw: string | undefined): Dashboardexport const dashboardTemplateEditorLogic = kea<dashboardTemplateEditorLogicType>([path(['scenes', 'dashboard', 'dashboardTemplateEditorLogic']),connect(() => ({- actions: [dashboardTemplatesLogic({ scope: 'default', templatesTabList: true }), ['getAllTemplates']],values: [featureFlagLogic, ['featureFlags']],})),actions({@@ -102,7 +106,7 @@ export const dashboardTemplateEditorLogic = kea<dashboardTemplateEditorLogicType},],}),- loaders(({ values, actions }) => ({+ loaders(({ values }) => ({dashboardTemplate: [undefined as DashboardTemplateEditorType | undefined | null,{@@ -193,7 +197,7 @@ export const dashboardTemplateEditorLogic = kea<dashboardTemplateEditorLogicTypeaction: async () => {try {await api.dashboardTemplates.update(id, { deleted: false })- refreshDashboardTemplateListsAfterMutation(actions.getAllTemplates)+ refreshDashboardTemplateListsAfterMutation()lemonToast.success(trimmedName? createElement(@@ -231,14 +235,14 @@ export const dashboardTemplateEditorLogic = kea<dashboardTemplateEditorLogicTypelisteners(({ values, actions }) => ({createDashboardTemplateSuccess: async () => {actions.closeDashboardTemplateEditor()- refreshDashboardTemplateListsAfterMutation(actions.getAllTemplates)+ refreshDashboardTemplateListsAfterMutation()},updateDashboardTemplateSuccess: async () => {actions.closeDashboardTemplateEditor()- refreshDashboardTemplateListsAfterMutation(actions.getAllTemplates)+ refreshDashboardTemplateListsAfterMutation()},deleteDashboardTemplateSuccess: async () => {- refreshDashboardTemplateListsAfterMutation(actions.getAllTemplates)+ refreshDashboardTemplateListsAfterMutation()},closeDashboardTemplateEditor: () => {actions.clear()diff --git a/frontend/src/scenes/dashboard/dashboards/templates/dashboardTemplateModalLogic.ts b/frontend/src/scenes/dashboard/dashboards/templates/dashboardTemplateModalLogic.tsindex 6675d606437f..e4ed3960229a 100644--- a/frontend/src/scenes/dashboard/dashboards/templates/dashboardTemplateModalLogic.ts+++ b/frontend/src/scenes/dashboard/dashboards/templates/dashboardTemplateModalLogic.ts@@ -1,4 +1,4 @@-import { actions, connect, kea, path, reducers } from 'kea'+import { actions, kea, path, reducers } from 'kea'import { loaders } from 'kea-loaders'import { lemonToast } from '@posthog/lemon-ui'@@ -15,9 +15,6 @@ export type CloseModalActionPayload = { readonly kind: 'closeModal' }export const dashboardTemplateModalLogic = kea<dashboardTemplateModalLogicType>([path(['scenes', 'dashboard', 'dashboards', 'templates', 'dashboardTemplateModalLogic']),- connect(() => ({- actions: [dashboardTemplatesLogic({ scope: 'default', templatesTabList: true }), ['getAllTemplates']],- })),actions({openCreate: (payload: DashboardTemplateEditorType) => ({ payload }),openEdit: (template: DashboardTemplateType) => ({ template }),@@ -121,7 +118,9 @@ export const dashboardTemplateModalLogic = kea<dashboardTemplateModalLogicType>(})lemonToast.success('Template updated')}- actions.getAllTemplates()+ dashboardTemplatesLogic+ .findMounted({ scope: 'default', templatesTabList: true })+ ?.actions.getAllTemplates()actions.closeModal()return true} catch (e: any) {