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.

fix(project-homepage): guard recent items before team loads (#57962)

posthog[bot]72e69ce2e77e
diff --git a/frontend/src/models/recentItemsModel.test.ts b/frontend/src/models/recentItemsModel.test.ts
new file mode 100644
index 000000000000..0781b58c605d
--- /dev/null
+++ b/frontend/src/models/recentItemsModel.test.ts
@@ -0,0 +1,85 @@
+import { MOCK_DEFAULT_TEAM } from 'lib/api.mock'
+
+import { expectLogic } from 'kea-test-utils'
+
+import api, { ApiConfig } from 'lib/api'
+import { teamLogic } from 'scenes/teamLogic'
+
+import type { FileSystemEntry } from '~/queries/schema/schema-general'
+import { initKeaTests } from '~/test/init'
+
+import { recentItemsModel } from './recentItemsModel'
+
+const recentItem = {
+ id: 'recent-item',
+ path: 'Dashboard',
+ type: 'dashboard',
+ ref: '1',
+ last_viewed_at: '2026-04-22T00:00:00Z',
+} as FileSystemEntry
+
+describe('recentItemsModel', () => {
+ let logic: ReturnType<typeof recentItemsModel.build>
+
+ beforeEach(() => {
+ initKeaTests(false)
+ })
+
+ afterEach(() => {
+ jest.restoreAllMocks()
+ })
+
+ it('does not load recent items on mount before the current team ID is known', async () => {
+ jest.spyOn(ApiConfig, 'hasCurrentTeamId').mockReturnValue(false)
+ const listRecents = jest.spyOn(api.fileSystem, 'list').mockResolvedValue({
+ count: 0,
+ results: [],
+ users: [],
+ })
+ const listSceneLogViews = jest.spyOn(api.fileSystemLogView, 'list').mockResolvedValue([])
+
+ logic = recentItemsModel()
+ logic.mount()
+
+ await Promise.resolve()
+
+ expect(listRecents).not.toHaveBeenCalled()
+ expect(listSceneLogViews).not.toHaveBeenCalled()
+ expect(logic.values.recents).toEqual([])
+ expect(logic.values.sceneLogViewsByRef).toEqual({})
+ })
+
+ it('loads recent items when the current team becomes available after mount', async () => {
+ let hasCurrentTeamId = false
+ jest.spyOn(ApiConfig, 'hasCurrentTeamId').mockImplementation(() => hasCurrentTeamId)
+ const listRecents = jest.spyOn(api.fileSystem, 'list').mockResolvedValue({
+ count: 1,
+ results: [recentItem],
+ users: [],
+ })
+ const listSceneLogViews = jest.spyOn(api.fileSystemLogView, 'list').mockResolvedValue([
+ { ref: 'DataManagementScene', type: 'scene', viewed_at: '2026-04-21T00:00:00Z' },
+ { ref: 'DataManagementScene', type: 'scene', viewed_at: '2026-04-22T00:00:00Z' },
+ ])
+
+ logic = recentItemsModel()
+ logic.mount()
+
+ await Promise.resolve()
+ expect(listRecents).not.toHaveBeenCalled()
+ expect(listSceneLogViews).not.toHaveBeenCalled()
+
+ hasCurrentTeamId = true
+
+ await expectLogic(logic, () => {
+ teamLogic.actions.loadCurrentTeamSuccess(MOCK_DEFAULT_TEAM)
+ })
+ .toDispatchActions(['loadRecentsSuccess', 'loadSceneLogViewsSuccess'])
+ .toMatchValues({
+ recents: [recentItem],
+ sceneLogViewsByRef: {
+ DataManagementScene: '2026-04-22T00:00:00Z',
+ },
+ })
+ })
+})
diff --git a/frontend/src/models/recentItemsModel.ts b/frontend/src/models/recentItemsModel.ts
index f87dfa3438e0..1c5e0fe80811 100644
--- a/frontend/src/models/recentItemsModel.ts
+++ b/frontend/src/models/recentItemsModel.ts
@@ -1,8 +1,9 @@
-import { actions, afterMount, kea, path, reducers } from 'kea'
+import { actions, afterMount, connect, kea, listeners, path, reducers } from 'kea'
import { loaders } from 'kea-loaders'
-import api from 'lib/api'
+import api, { ApiConfig } from 'lib/api'
import { permanentlyMount } from 'lib/utils/kea-logic-builders'
+import { teamLogic } from 'scenes/teamLogic'
import { FileSystemEntry } from '~/queries/schema/schema-general'
@@ -13,6 +14,10 @@ const RECENTS_FETCH_LIMIT = 20
export const recentItemsModel = kea<recentItemsModelType>([
path(['models', 'recentItemsModel']),
+ connect(() => ({
+ actions: [teamLogic, ['loadCurrentTeamSuccess']],
+ })),
+
actions({
recordView: (type: string, ref: string) => ({ type, ref }),
}),
@@ -22,6 +27,10 @@ export const recentItemsModel = kea<recentItemsModelType>([
[] as FileSystemEntry[],
{
loadRecents: async () => {
+ if (!ApiConfig.hasCurrentTeamId()) {
+ return []
+ }
+
const response = await api.fileSystem.list({
orderBy: '-last_viewed_at',
notType: 'folder',
@@ -35,6 +44,10 @@ export const recentItemsModel = kea<recentItemsModelType>([
{} as Record<string, string>,
{
loadSceneLogViews: async () => {
+ if (!ApiConfig.hasCurrentTeamId()) {
+ return {}
+ }
+
const results = await api.fileSystemLogView.list({ type: 'scene' })
const record: Record<string, string> = {}
for (const { ref, viewed_at } of results) {
@@ -90,7 +103,22 @@ export const recentItemsModel = kea<recentItemsModelType>([
],
}),
+ listeners(({ actions }) => ({
+ loadCurrentTeamSuccess: ({ currentTeam }) => {
+ if (!currentTeam) {
+ return
+ }
+
+ actions.loadRecents()
+ actions.loadSceneLogViews()
+ },
+ })),
+
afterMount(({ actions }) => {
+ if (!ApiConfig.hasCurrentTeamId()) {
+ return
+ }
+
actions.loadRecents()
actions.loadSceneLogViews()
}),