: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
feat(project-tree): lazy-load unfiled reconciliation (#101243)
Matt Pua4711ba71cb5e
diff --git a/frontend/src/layout/panel-layout/ProjectTree/ProjectTree.tsx b/frontend/src/layout/panel-layout/ProjectTree/ProjectTree.tsxindex e07ae80f0e85..0404eceb368d 100644--- a/frontend/src/layout/panel-layout/ProjectTree/ProjectTree.tsx+++ b/frontend/src/layout/panel-layout/ProjectTree/ProjectTree.tsx@@ -122,7 +122,7 @@ export function ProjectTree(props: ProjectTreeProps): JSX.Element {const [uniqueKey] = useState(() => `project-tree-${counter++}`)const { viableItems, shortcutEntryIdMap } = useValues(projectTreeDataLogic)const { reorderShortcutByDrag } = useActions(projectTreeDataLogic)- const projectTreeLogicProps = { key: logicKey ?? uniqueKey, root }+ const projectTreeLogicProps = { key: logicKey ?? uniqueKey, root, isActiveInPanel }const {fullFileSystemFiltered,lastViewedId,@@ -396,7 +396,14 @@ export function ProjectTree(props: ProjectTreeProps): JSX.Element {return (<ContextMenuGroup className="group/colorful-product-icons colorful-product-icons-true">- <MenuItems item={item} type="context" root={root} onlyTree={onlyTree} logicKey={logicKey} />+ <MenuItems+ item={item}+ type="context"+ root={root}+ onlyTree={onlyTree}+ logicKey={logicKey}+ isActiveInPanel={isActiveInPanel}+ /></ContextMenuGroup>)}}@@ -410,7 +417,14 @@ export function ProjectTree(props: ProjectTreeProps): JSX.Element {return (<DropdownMenuGroup className="group/colorful-product-icons colorful-product-icons-true">- <MenuItems item={item} type="dropdown" root={root} onlyTree={onlyTree} logicKey={logicKey} />+ <MenuItems+ item={item}+ type="dropdown"+ root={root}+ onlyTree={onlyTree}+ logicKey={logicKey}+ isActiveInPanel={isActiveInPanel}+ /></DropdownMenuGroup>)}}diff --git a/frontend/src/layout/panel-layout/ProjectTree/menus/MenuItems.tsx b/frontend/src/layout/panel-layout/ProjectTree/menus/MenuItems.tsxindex 502dcaf1bf43..a0ce8fb2355a 100644--- a/frontend/src/layout/panel-layout/ProjectTree/menus/MenuItems.tsx+++ b/frontend/src/layout/panel-layout/ProjectTree/menus/MenuItems.tsx@@ -54,6 +54,7 @@ interface MenuItemsProps {root?: stringonlyTree?: booleanlogicKey?: string+ isActiveInPanel?: booleanshowSelectMenuOption?: boolean}@@ -65,6 +66,7 @@ export function MenuItems({root,onlyTree,logicKey,+ isActiveInPanel,showSelectMenuOption = true,}: MenuItemsProps): JSX.Element {const [uniqueKey] = useState(() => `project-tree-${counter++}`)@@ -74,7 +76,7 @@ export function MenuItems({const { deleteGroupType } = useActions(groupAnalyticsConfigLogic)const { enabledToolPaths: customProductsSelectedPaths } = useValues(customProductsLogic)- const projectTreeLogicProps = { key: logicKey ?? uniqueKey, root }+ const projectTreeLogicProps = { key: logicKey ?? uniqueKey, root, isActiveInPanel }const { checkedItems, checkedItemCountNumeric, checkedItemsArray } = useValues(projectTreeLogic(projectTreeLogicProps))diff --git a/frontend/src/layout/panel-layout/ProjectTree/projectTreeDataLogic.test.ts b/frontend/src/layout/panel-layout/ProjectTree/projectTreeDataLogic.test.tsindex 482917bf24ef..026d8b4c947d 100644--- a/frontend/src/layout/panel-layout/ProjectTree/projectTreeDataLogic.test.ts+++ b/frontend/src/layout/panel-layout/ProjectTree/projectTreeDataLogic.test.ts@@ -7,6 +7,7 @@ import { initKeaTests } from '~/test/init'import { customProductsLogic } from './customProductsLogic'import { MovedItem, projectTreeDataLogic } from './projectTreeDataLogic'+import { projectTreeLogic } from './projectTreeLogic'// pluralize() joins the count to the unit with a non-breaking space, which no reader can see in an assertion.const toastText = (message: unknown): string => String(message).replace(/\u00a0/g, ' ')@@ -24,7 +25,7 @@ describe('projectTreeDataLogic', () => {initKeaTests()logic = projectTreeDataLogic()unmount = logic.mount()- await expectLogic(logic).toDispatchActions(['loadUnfiledItemsSuccess'])+ await expectLogic(logic).toDispatchActions(['loadFolderSuccess'])jest.clearAllMocks()})@@ -51,7 +52,6 @@ describe('projectTreeDataLogic', () => {it('handles null unfiled item responses', async () => {jest.mocked(api.fileSystem.unfiled).mockResolvedValueOnce(null)-await expectLogic(logic, () => {logic.actions.loadUnfiledItems()})@@ -61,6 +61,52 @@ describe('projectTreeDataLogic', () => {expect(api.fileSystem.list).not.toHaveBeenCalled()})+ it('reconciles unfiled items when the project tree becomes active', async () => {+ const rootlessTree = projectTreeLogic({ key: 'project-tree' })+ rootlessTree.mount()++ const projectTree = projectTreeLogic({ key: 'project-tree', root: 'project://', isActiveInPanel: true })++ await expectLogic(logic, () => {+ projectTree.mount()+ }).toDispatchActions(['loadUnfiledItems', 'loadUnfiledItemsSuccess'])++ projectTree.unmount()+ rootlessTree.unmount()+ })++ it('does not reconcile unfiled items when the project tree is hidden', () => {+ const projectTree = projectTreeLogic({ key: 'project-tree', root: 'project://', isActiveInPanel: false })++ projectTree.mount()++ expect(api.fileSystem.unfiled).not.toHaveBeenCalled()+ projectTree.unmount()+ })++ it('reconciles unfiled items when a non-panel project tree opens', async () => {+ const projectTree = projectTreeLogic({ key: 'folder-select', root: 'project://' })++ await expectLogic(logic, () => {+ projectTree.mount()+ }).toDispatchActions(['loadUnfiledItems', 'loadUnfiledItemsSuccess'])++ projectTree.unmount()+ })++ it('does not load Unfiled after the root folder loads in a hidden project tree', async () => {+ const projectTree = projectTreeLogic({ key: 'project-tree', root: 'project://', isActiveInPanel: false })+ projectTree.mount()+ await expectLogic(logic).toFinishAllListeners()+ jest.clearAllMocks()++ logic.actions.loadFolderSuccess('', [], false, 0)+ await expectLogic(logic).toFinishAllListeners()++ expect(api.fileSystem.list).not.toHaveBeenCalled()+ projectTree.unmount()+ })+it('loads unfiled folders when the count response reports items', async () => {logic.actions.createSavedItem({ id: 'saved-insight', path: 'Unfiled/Insights/Saved insight', type: 'insight' })jest.mocked(api.fileSystem.unfiled).mockResolvedValueOnce({ count: 1 })diff --git a/frontend/src/layout/panel-layout/ProjectTree/projectTreeDataLogic.tsx b/frontend/src/layout/panel-layout/ProjectTree/projectTreeDataLogic.tsxindex b4c5667636e6..b4b7a9f8819d 100644--- a/frontend/src/layout/panel-layout/ProjectTree/projectTreeDataLogic.tsx+++ b/frontend/src/layout/panel-layout/ProjectTree/projectTreeDataLogic.tsx@@ -1823,7 +1823,6 @@ export const projectTreeDataLogic = kea<projectTreeDataLogicType>([})),afterMount(({ actions }) => {actions.loadFolder('')- actions.loadUnfiledItems()actions.loadShortcuts()}),])diff --git a/frontend/src/layout/panel-layout/ProjectTree/projectTreeLogic.tsx b/frontend/src/layout/panel-layout/ProjectTree/projectTreeLogic.tsxindex 7b16c93e85ba..0934d966ef3c 100644--- a/frontend/src/layout/panel-layout/ProjectTree/projectTreeLogic.tsx+++ b/frontend/src/layout/panel-layout/ProjectTree/projectTreeLogic.tsx@@ -69,6 +69,7 @@ export interface ProjectTreeLogicProps {root?: stringincludeRoot?: booleanhideFolders?: string[]+ isActiveInPanel?: boolean}const FOLDER_LOADING = [@@ -94,6 +95,8 @@ export interface projectTreeLogicValues {loadingPaths: Record<string, boolean> // projectTreeDataLogicshortcutData: FileSystemEntry[] // projectTreeDataLogicsortedItems: FileSystemEntry[] // projectTreeDataLogic+ unfiledItems: boolean // projectTreeDataLogic+ unfiledItemsLoading: boolean // projectTreeDataLogicusers: Record<string, UserBasicType> // projectTreeDataLogicviableItems: FileSystemEntry[] // projectTreeDataLogicviableItemsById: Record<string, FileSystemEntry> // projectTreeDataLogic@@ -205,6 +208,9 @@ export interface projectTreeLogicActions {hasMore: booleanoffsetIncrease: number} // projectTreeDataLogic+ loadUnfiledItems: () => {+ value: true+ } // projectTreeDataLogicmoveItem: (item: FileSystemEntry,newPath: string,@@ -217,12 +223,18 @@ export interface projectTreeLogicActions {projectTreeLogicKey: string} // projectTreeDataLogicmoveItems: (- moves: { item: FileSystemEntry; newPath: string }[],+ moves: {+ item: FileSystemEntry+ newPath: string+ }[],force: boolean,projectTreeLogicKey: string) => {force: boolean- moves: { item: FileSystemEntry; newPath: string }[]+ moves: {+ item: FileSystemEntry+ newPath: string+ }[]projectTreeLogicKey: string} // projectTreeDataLogicmovedItem: (@@ -469,8 +481,8 @@ export interface projectTreeLogicMeta {recentResultsLoading: boolean,sortMethod: ProjectTreeSortMethod,onlyFolders: boolean,- getStaticTreeItems: (searchTerm: string, onlyFolders: boolean) => TreeDataItem[],- getCustomProductTreeItems: (searchTerm: string) => TreeDataItem[],+ getStaticTreeItems: (searchTerm: string, onlyFolders: boolean) => TreeDataItem[], // projectTreeDataLogic+ getCustomProductTreeItems: (searchTerm: string) => TreeDataItem[], // projectTreeDataLogicarg: any) => TreeDataItem[]fullFileSystemFiltered: (@@ -500,6 +512,15 @@ export type projectTreeLogicType = MakeLogicType<projectTreeLogicMeta>+const shouldLoadUnfiledItems = (+ props: ProjectTreeLogicProps,+ values: Pick<projectTreeLogicValues, 'unfiledItems' | 'unfiledItemsLoading'>+): boolean =>+ props.root?.startsWith('project://') === true &&+ props.isActiveInPanel !== false &&+ !values.unfiledItems &&+ !values.unfiledItemsLoading+export const projectTreeLogic = kea<projectTreeLogicType>([path(['layout', 'navigation-3000', 'components', 'projectTreeLogic']),props({} as ProjectTreeLogicProps),@@ -522,6 +543,8 @@ export const projectTreeLogic = kea<projectTreeLogicType>(['getStaticTreeItems','getCustomProductTreeItems','shortcutData',+ 'unfiledItems',+ 'unfiledItemsLoading',],],actions: [@@ -545,6 +568,7 @@ export const projectTreeLogic = kea<projectTreeLogicType>(['moveItems','linkItem','pruneClosedFolders',+ 'loadUnfiledItems',],],})),@@ -1208,7 +1232,7 @@ export const projectTreeLogic = kea<projectTreeLogicType>([actions.pruneClosedFolders(values.expandedFolders)},loadFolderSuccess: ({ folder }) => {- if (folder === '') {+ if (props.root?.startsWith('project://') && props.isActiveInPanel === true && folder === '') {const rootItems = values.folders['']if (rootItems.length < 5) {actions.toggleFolderOpen('project://Unfiled', true)@@ -1632,8 +1656,10 @@ export const projectTreeLogic = kea<projectTreeLogicType>([} else {actions.loadFolder('')}- // Same gate as the subscription: only project:// trees handle breadcrumb-driven visibility.const isProjectRoot = props.root === undefined || props.root.startsWith('project://')+ if (shouldLoadUnfiledItems(props, values)) {+ actions.loadUnfiledItems()+ }if (values.projectTreeRef && isProjectRoot) {actions.assureVisibility(values.projectTreeRef)}@@ -1655,6 +1681,11 @@ export const projectTreeLogic = kea<projectTreeLogicType>([actions.loadFolderIfNotLoaded(props.root)}}+ const projectPanelStateChanged =+ props.root !== oldProps.root || props.isActiveInPanel !== oldProps.isActiveInPanel+ if (projectPanelStateChanged && shouldLoadUnfiledItems(props, values)) {+ actions.loadUnfiledItems()+ }}),])diff --git a/frontend/src/layout/panel-layout/navbar/PanelLayoutPanels.test.tsx b/frontend/src/layout/panel-layout/navbar/PanelLayoutPanels.test.tsxindex 7e6e165264a9..e9d7d6ff7a7b 100644--- a/frontend/src/layout/panel-layout/navbar/PanelLayoutPanels.test.tsx+++ b/frontend/src/layout/panel-layout/navbar/PanelLayoutPanels.test.tsx@@ -7,7 +7,9 @@ import { PanelLayoutPanels } from './PanelLayoutPanels'jest.mock('../ProjectTree/ProjectTree', () => ({PROJECT_TREE_KEY: 'project-tree',- ProjectTree: ({ root }: { root: string }) => <div data-attr="mock-tree" data-root={root} />,+ ProjectTree: ({ root, isActiveInPanel }: { root: string; isActiveInPanel: boolean }) => (+ <div data-attr="mock-tree" data-root={root} data-active={isActiveInPanel} />+ ),}))jest.mock('lib/components/NotificationsMenu/NotificationsPanel', () => ({NotificationsPanel: () => <div data-attr="mock-notifications" />,@@ -22,10 +24,11 @@ describe('PanelLayoutPanels', () => {panelLayoutLogic.mount()})- function renderedTrees(container: HTMLElement): { root: string | null; hidden: boolean }[] {+ function renderedTrees(container: HTMLElement): { root: string | null; hidden: boolean; active: boolean }[] {return Array.from(container.querySelectorAll('[data-attr="mock-tree"]')).map((tree) => ({root: tree.getAttribute('data-root'),hidden: !!tree.closest('.hidden'),+ active: tree.getAttribute('data-active') === 'true',}))}@@ -33,20 +36,21 @@ describe('PanelLayoutPanels', () => {const { container } = render(<PanelLayoutPanels />)expect(renderedTrees(container)).toEqual([])+ act(() => panelLayoutLogic.actions.showLayoutPanel(true))act(() => panelLayoutLogic.actions.setActivePanelIdentifier('Project'))- expect(renderedTrees(container)).toEqual([{ root: 'project://', hidden: false }])+ expect(renderedTrees(container)).toEqual([{ root: 'project://', hidden: false, active: true }])// Switching must not tear down the project tree — it stays in the DOM, hidden.act(() => panelLayoutLogic.actions.setActivePanelIdentifier('Products'))expect(renderedTrees(container)).toEqual([- { root: 'project://', hidden: true },- { root: 'products://', hidden: false },+ { root: 'project://', hidden: true, active: false },+ { root: 'products://', hidden: false, active: true },])act(() => panelLayoutLogic.actions.clearActivePanelIdentifier())expect(renderedTrees(container)).toEqual([- { root: 'project://', hidden: true },- { root: 'products://', hidden: true },+ { root: 'project://', hidden: true, active: false },+ { root: 'products://', hidden: true, active: false },])})diff --git a/frontend/src/lib/components/FileSystem/FolderSelect/FolderSelect.tsx b/frontend/src/lib/components/FileSystem/FolderSelect/FolderSelect.tsxindex 88964abc2be4..5ba27c7b673f 100644--- a/frontend/src/lib/components/FileSystem/FolderSelect/FolderSelect.tsx+++ b/frontend/src/lib/components/FileSystem/FolderSelect/FolderSelect.tsx@@ -28,6 +28,7 @@ export interface FolderSelectProps {includeProtocol?: boolean/** Include root item in the tree as a selectable item */includeRoot?: boolean+ isActiveInPanel?: boolean}/** Input component for selecting a folder */@@ -40,9 +41,10 @@ export function FolderSelect({className,includeProtocol,includeRoot,+ isActiveInPanel,}: FolderSelectProps): JSX.Element {const [key] = useState(() => `folder-select-${counter++}`)- const props: ProjectTreeLogicProps = { key, defaultOnlyFolders: true, root, includeRoot }+ const props: ProjectTreeLogicProps = { key, defaultOnlyFolders: true, root, includeRoot, isActiveInPanel }const inputRef = useRef<HTMLInputElement>(null)const { searchTerm, expandedSearchFolders, expandedFolders, fullFileSystemFiltered, editingItemId } = useValues(diff --git a/frontend/src/lib/components/FileSystem/ItemSelectModal/ItemSelectModal.tsx b/frontend/src/lib/components/FileSystem/ItemSelectModal/ItemSelectModal.tsxindex 5429b6816ced..97236b04cce6 100644--- a/frontend/src/lib/components/FileSystem/ItemSelectModal/ItemSelectModal.tsx+++ b/frontend/src/lib/components/FileSystem/ItemSelectModal/ItemSelectModal.tsx@@ -75,10 +75,16 @@ export function ItemSelectModalButton({ buttonProps }: ItemSelectModalButtonPropexport function ItemSelectModal({ className, includeProtocol, includeRoot }: ItemSelectModalProps): JSX.Element {const [treeRoot, setTreeRoot] = useState('project://')const [key] = useState(() => `item-select-${counter++}`)- const props: ProjectTreeLogicProps = { key, root: treeRoot, includeRoot, hideFolders: ['shortcuts://'] }const inputRef = useRef<HTMLInputElement>(null)const [selectedItem, setSelectedItem] = useState<TreeDataItem | null>(null)const { isOpen } = useValues(itemSelectModalLogic)+ const props: ProjectTreeLogicProps = {+ key,+ root: treeRoot,+ includeRoot,+ hideFolders: ['shortcuts://'],+ isActiveInPanel: isOpen,+ }const { closeItemSelectModal, submitForm, setFormValue } = useActions(itemSelectModalLogic)const { searchTerm, expandedSearchFolders, expandedFolders, fullFileSystemFiltered, editingItemId } = useValues(projectTreeLogic(props)diff --git a/frontend/src/lib/components/FileSystem/LinkTo/LinkTo.tsx b/frontend/src/lib/components/FileSystem/LinkTo/LinkTo.tsxindex 57ffe50e9e3c..7282c0a51e53 100644--- a/frontend/src/lib/components/FileSystem/LinkTo/LinkTo.tsx+++ b/frontend/src/lib/components/FileSystem/LinkTo/LinkTo.tsx@@ -54,7 +54,12 @@ export function LinkToModal(): JSX.Element {<div className="w-192 max-w-full"><Form logic={linkToLogic} formKey="form"><LemonField name="folder">- <FolderSelect root="project://" includeRoot className="h-[60vh] min-h-[200px]" />+ <FolderSelect+ root="project://"+ includeRoot+ isActiveInPanel={isOpen}+ className="h-[60vh] min-h-[200px]"+ /></LemonField></Form></div>diff --git a/frontend/src/lib/components/FileSystem/MoveTo/MoveTo.tsx b/frontend/src/lib/components/FileSystem/MoveTo/MoveTo.tsxindex acef8e7679cd..780e6816f1d9 100644--- a/frontend/src/lib/components/FileSystem/MoveTo/MoveTo.tsx+++ b/frontend/src/lib/components/FileSystem/MoveTo/MoveTo.tsx@@ -52,7 +52,12 @@ export function MoveToModal(): JSX.Element {<div className="w-192 max-w-full"><Form logic={moveToLogic} formKey="form"><LemonField name="folder">- <FolderSelect root="project://" includeRoot className="h-[60vh] min-h-[200px]" />+ <FolderSelect+ root="project://"+ includeRoot+ isActiveInPanel={isOpen}+ className="h-[60vh] min-h-[200px]"+ /></LemonField></Form></div>