: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
refactor(frontend): remove defunct tabId from actions scenes (#62028)
Paul D'Ambra23cb4e1f052f
diff --git a/products/actions/frontend/components/ActionHogFunctions.tsx b/products/actions/frontend/components/ActionHogFunctions.tsxindex 546079974d34..88392d5c0901 100644--- a/products/actions/frontend/components/ActionHogFunctions.tsx+++ b/products/actions/frontend/components/ActionHogFunctions.tsx@@ -10,13 +10,13 @@ import { actionEditLogic } from '../logics/actionEditLogic'import { actionLogic } from '../logics/actionLogic'export function ActionHogFunctions(): JSX.Element | null {- const { action, tabId } = useValues(actionLogic)- return !action ? null : <Functions action={action} tabId={tabId} />+ const { action } = useValues(actionLogic)+ return !action ? null : <Functions action={action} />}-const Functions = ({ action, tabId }: { action: ActionType; tabId?: string }): JSX.Element => {+const Functions = ({ action }: { action: ActionType }): JSX.Element => {const { hasCohortFilters, actionChanged, showCohortDisablesFunctionsWarning } = useValues(- actionEditLogic({ id: action?.id, action, tabId })+ actionEditLogic({ id: action?.id, action }))return (<LemonCollapsediff --git a/products/actions/frontend/logics/actionEditLogic.tsx b/products/actions/frontend/logics/actionEditLogic.tsxindex fc007c43676d..8593e6f5ffd1 100644--- a/products/actions/frontend/logics/actionEditLogic.tsx+++ b/products/actions/frontend/logics/actionEditLogic.tsx@@ -10,7 +10,6 @@ import { SetupTaskId, globalSetupLogic } from 'lib/components/ProductSetup'import { lemonToast } from 'lib/lemon-ui/LemonToast/LemonToast'import { Link } from 'lib/lemon-ui/Link'import { eventDefinitionsTableLogic } from 'scenes/data-management/events/eventDefinitionsTableLogic'-import { sceneLogic } from 'scenes/sceneLogic'import { urls } from 'scenes/urls'import { deleteFromTree, getLastNewFolder, refreshTreeItem } from '~/layout/panel-layout/ProjectTree/projectTreeLogic'@@ -37,7 +36,6 @@ export interface SetActionProps {export interface ActionEditLogicProps {id: numberaction?: ActionType | null- tabId?: string}export const DEFAULT_ACTION_STEP: ActionStepType = {@@ -48,9 +46,7 @@ export const DEFAULT_ACTION_STEP: ActionStepType = {export const actionEditLogic = kea<actionEditLogicType>([path((key) => ['scenes', 'actions', 'actionEditLogic', key]),props({} as ActionEditLogicProps),- // Key by tabId AND id so each tab preserves its own form state across tab switches.- // Fall back to 'notab' for non-scene mounts (e.g. tests, side panel) to stay backwards-compatible.- key((props) => `${props.tabId || 'notab'}:${props.id || 'new'}`),+ key((props) => `${props.id || 'new'}`),connect(() => ({actions: [actionsModel,@@ -166,7 +162,7 @@ export const actionEditLogic = kea<actionEditLogicType>([router.actions.push(urls.action(action.id))} else {const id = parseInt(props.id.toString()) // props.id can be a string- const logic = actionLogic.findMounted({ tabId: props.tabId, id })+ const logic = actionLogic.findMounted({ id })logic?.actions.loadActionSuccess(action)}@@ -315,28 +311,6 @@ export const actionEditLogic = kea<actionEditLogicType>([return false}- // Skip the prompt for tab switches — our tab still exists, the logic stays mounted- // via the scene-logic cache, and the form state is preserved. A tab switch shows up- // in one of two ways at beforeUnload time:- // - switching AWAY: sceneLogic.activateTab() has already moved active to another- // tab before router.push fires, so activeTabId !== our tabId.- // - switching BACK: active is now us again, and the push target is our own tab's- // stored pathname.- // Anything else (in-tab navigation, closing our tab) should still prompt.- const myTabId = logic.props.tabId- const scene = sceneLogic.findMounted()- if (myTabId && scene && newLocation) {- const myTab = scene.values.tabs.find((t) => t.id === myTabId)- if (myTab) {- if (scene.values.activeTabId !== myTabId) {- return false- }- if (myTab.pathname === newLocation.pathname) {- return false- }- }- }-return true},message: 'Leave action?\nChanges you made will be discarded.',diff --git a/products/actions/frontend/logics/actionLogic.ts b/products/actions/frontend/logics/actionLogic.tsindex c40beabb0150..d497720693a0 100644--- a/products/actions/frontend/logics/actionLogic.ts+++ b/products/actions/frontend/logics/actionLogic.ts@@ -15,15 +15,11 @@ import type { actionLogicType } from './actionLogicType'export interface ActionLogicProps {id: ActionType['id']- tabId?: string}export const actionLogic = kea<actionLogicType>([props({} as ActionLogicProps),- // Key by tabId AND id so each tab preserves its own mounted scene-logic instance across- // tab switches. The scene-logic cache keeps this instance alive while another tab is- // active, which in turn keeps the held actionEditLogic alive (and its form state intact).- key((props) => `${props.tabId || 'notab'}:${props.id || 'new'}`),+ key((props) => `${props.id || 'new'}`),connect(() => ({values: [featureFlagLogic, ['featureFlags']],})),@@ -80,7 +76,6 @@ export const actionLogic = kea<actionLogicType>([],})),selectors({- tabId: [() => [(_, p: ActionLogicProps) => p.tabId], (tabId): string | undefined => tabId],projectTreeRef: [(_, p) => [p.id], (id): ProjectTreeRef => ({ type: 'action', ref: String(id) })],hasCohortFilters: [(s) => [s.action],@@ -92,9 +87,7 @@ export const actionLogic = kea<actionLogicType>([breadcrumbs: [(s) => [s.action,- (state, props) =>- actionEditLogic.findMounted({ tabId: props?.tabId, id: props?.id })?.selectors.action(state).name ||- null,+ (state, props) => actionEditLogic.findMounted({ id: props?.id })?.selectors.action(state).name || null,],(action, inProgressName): Breadcrumb[] => [{diff --git a/products/actions/frontend/pages/Action.tsx b/products/actions/frontend/pages/Action.tsxindex 47958c78fec8..9b557944dcdc 100644--- a/products/actions/frontend/pages/Action.tsx+++ b/products/actions/frontend/pages/Action.tsx@@ -12,21 +12,20 @@ export const scene: SceneExport<ActionLogicProps> = {paramsToProps: ({ params: { id } }) => ({ id: parseInt(id) }),}-export function Action({ id, tabId }: ActionLogicProps): JSX.Element {- // Use the scene-bound logic (BindLogic in App.tsx supplies tabId), so we don't need to- // duplicate the key props here.+export function Action({ id }: ActionLogicProps): JSX.Element {+ // Use the scene-bound logic (BindLogic in App.tsx supplies the key props), so we don't need+ // to duplicate them here.const { action, actionLoading } = useValues(actionLogic)return (<ActionEditid={id}- tabId={tabId}action={action}actionLoading={actionLoading}// Attach actionEditLogic to the scene-kept actionLogic so the form state survives- // tab switches: sceneLogic keeps actionLogic mounted per tab, and useAttachedLogic- // keeps actionEditLogic alive for as long as actionLogic is mounted.- attachTo={actionLogic({ id, tabId })}+ // React remounts: useAttachedLogic keeps actionEditLogic alive for as long as+ // actionLogic is mounted.+ attachTo={actionLogic({ id })}/>)}diff --git a/products/actions/frontend/pages/ActionEdit.tsx b/products/actions/frontend/pages/ActionEdit.tsxindex 22b4d1000ca0..fef249bc8dcb 100644--- a/products/actions/frontend/pages/ActionEdit.tsx+++ b/products/actions/frontend/pages/ActionEdit.tsx@@ -70,17 +70,16 @@ export interface ActionEditProps extends ActionEditLogicProps {attachTo?: BuiltLogic<Logic> | LogicWrapper<Logic>}-export function ActionEdit({ action: loadedAction, id, tabId, actionLoading, attachTo }: ActionEditProps): JSX.Element {+export function ActionEdit({ action: loadedAction, id, actionLoading, attachTo }: ActionEditProps): JSX.Element {const logicProps: ActionEditLogicProps = {id,action: loadedAction,- tabId,}const { isComplete } = useValues(actionLogic)const logic = actionEditLogic(logicProps)- // Attach to the scene-kept actionLogic so the form state persists across tab switches:- // sceneLogic keeps actionLogic mounted per tab, and useAttachedLogic keeps actionEditLogic- // alive for as long as actionLogic is mounted, even when this component unmounts.+ // Attach to the scene-kept actionLogic so the form state persists across React remounts:+ // useAttachedLogic keeps actionEditLogic alive for as long as actionLogic is mounted, even+ // when this component unmounts.useAttachedLogic(logic, attachTo)const { action, actionChanged, isActionSubmitting } = useValues(logic)const { submitAction, deleteAction, setActionValue, setAction, setOriginalAction } = useActions(logic)