: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(navigation): clear recents when switching projects (#72006)
posthog[bot]79eae9a431d2
diff --git a/frontend/src/models/recentItemsModel.test.ts b/frontend/src/models/recentItemsModel.test.tsindex 8706ddb33927..b8058b49a4fd 100644--- a/frontend/src/models/recentItemsModel.test.ts+++ b/frontend/src/models/recentItemsModel.test.ts@@ -83,6 +83,37 @@ describe('recentItemsModel', () => {})})+ it('clears the previous project items on team switch so stale recents are not clickable', async () => {+ jest.spyOn(ApiConfig, 'hasCurrentTeamId').mockReturnValue(true)+ jest.spyOn(api.fileSystem, 'list').mockResolvedValue({+ count: 1,+ results: [recentItem],+ users: [],+ })+ jest.spyOn(api.fileSystemLogView, 'list').mockResolvedValue([+ { ref: 'DataManagementScene', type: 'scene', viewed_at: '2026-04-22T00:00:00Z' },+ ])++ logic = recentItemsModel()+ logic.mount()++ await expectLogic(logic)+ .toDispatchActions(['loadRecentsSuccess', 'loadSceneLogViewsSuccess'])+ .toMatchValues({+ recents: [recentItem],+ recentsHasLoaded: true,+ sceneLogViewsHasLoaded: true,+ })++ // Switching projects must wipe the old list synchronously, before the fresh load resolves,+ // so its relative hrefs can't be clicked into the new project and 404.+ teamLogic.actions.loadCurrentTeamSuccess(MOCK_DEFAULT_TEAM)+ expect(logic.values.recents).toEqual([])+ expect(logic.values.sceneLogViewsByRef).toEqual({})+ expect(logic.values.recentsHasLoaded).toBe(false)+ expect(logic.values.sceneLogViewsHasLoaded).toBe(false)+ })+it('degrades to empty fallbacks when the loaders hit a fetch failure', async () => {jest.spyOn(ApiConfig, 'hasCurrentTeamId').mockReturnValue(true)jest.spyOn(api.fileSystem, 'list').mockRejectedValue(new TypeError('Failed to fetch'))diff --git a/frontend/src/models/recentItemsModel.ts b/frontend/src/models/recentItemsModel.tsindex 4cfc2cd24df2..f6e9681ab09a 100644--- a/frontend/src/models/recentItemsModel.ts+++ b/frontend/src/models/recentItemsModel.ts@@ -166,6 +166,10 @@ export const recentItemsModel = kea<recentItemsModelType>([recents: [[] as FileSystemEntry[],{+ // Drop the previous project's items the moment we switch teams. Otherwise they stay+ // visible and clickable until the reload lands, and their relative hrefs (e.g.+ // /surveys/{pk}) resolve under the new project and 404.+ loadCurrentTeamSuccess: (state, { currentTeam }) => (currentTeam ? [] : state),recordView: (state, { type, ref }) => {const idx = state.findIndex((e) => e.type === type && e.ref === ref)if (idx < 0) {@@ -179,6 +183,7 @@ export const recentItemsModel = kea<recentItemsModelType>([sceneLogViewsByRef: [{} as Record<string, string>,{+ loadCurrentTeamSuccess: (state, { currentTeam }) => (currentTeam ? {} : state),recordView: (state, { type, ref }) => {if (type !== 'scene') {return state@@ -190,6 +195,9 @@ export const recentItemsModel = kea<recentItemsModelType>([recentsHasLoaded: [false,{+ // Reset to false on team switch so consumers show the loading state instead of the+ // now-cleared previous project's recents while the fresh list loads.+ loadCurrentTeamSuccess: (state, { currentTeam }) => (currentTeam ? false : state),loadRecentsSuccess: () => true,loadRecentsFailure: () => true,},@@ -197,6 +205,7 @@ export const recentItemsModel = kea<recentItemsModelType>([sceneLogViewsHasLoaded: [false,{+ loadCurrentTeamSuccess: (state, { currentTeam }) => (currentTeam ? false : state),loadSceneLogViewsSuccess: () => true,loadSceneLogViewsFailure: () => true,},