π€― LobeHub - Super-Agents on Your Team. Add super-agents to the chats your team already uses.They take on work by themselves and get better every week.
TypeScript agentagent-collaborationagent-harnessloop-engineeringmcppersonal-assistantproactive-agentskillssuper-agenttask-management
π fix(topic): stop project View all from breaking every topic list (#20798)
YuTengjing2a10d34c58b2
diff --git a/src/features/AgentSidebar/Topic/TopicListScope.tsx b/src/features/AgentSidebar/Topic/TopicListScope.tsxindex b07bb2a77d2..35973e3e56c 100644--- a/src/features/AgentSidebar/Topic/TopicListScope.tsx+++ b/src/features/AgentSidebar/Topic/TopicListScope.tsx@@ -3,3 +3,17 @@ import { createContext, use } from 'react';/** Host identity keeps the shared list inside its Project route and data scope. */export const TopicListScopeContext = createContext<{ projectId: string } | null>(null);export const useTopicListScope = () => use(TopicListScopeContext);++/**+ * Rows the Project sidebar reveals beyond `topicPageSize`. Owned by the host+ * so the list and its siblings (the collapse-all toggle) slice the same rows.+ * It must stay local: growing the global `topicPageSize` instead pushed it past+ * the server's `getTopics` page-size cap of 100 and broke every topic list.+ */+export interface TopicListRevealState {+ extraRows: number;+ revealMore: () => void;+}++export const TopicListRevealContext = createContext<TopicListRevealState | null>(null);+export const useTopicListReveal = () => use(TopicListRevealContext);diff --git a/src/features/AgentSidebar/Topic/useScopedTopics.test.ts b/src/features/AgentSidebar/Topic/useScopedTopics.test.tsindex 4f527396ab5..ea99c1bd9e2 100644--- a/src/features/AgentSidebar/Topic/useScopedTopics.test.ts+++ b/src/features/AgentSidebar/Topic/useScopedTopics.test.ts@@ -1,12 +1,13 @@/** @vitest-environment happy-dom */-import { renderHook } from '@testing-library/react';-import { createElement, type PropsWithChildren } from 'react';+import { act, renderHook } from '@testing-library/react';+import { createElement, type PropsWithChildren, useState } from 'react';import { beforeEach, describe, expect, it, vi } from 'vitest';-import { TopicListScopeContext } from './TopicListScope';+import { TopicListRevealContext, TopicListScopeContext } from './TopicListScope';import { useScopedSidebarTopics } from './useScopedTopics';const fixture = vi.hoisted(() => ({ topicId: undefined as string | undefined }));+const updateSystemStatus = vi.hoisted(() => vi.fn());const rows = [{id: 'old',@@ -52,15 +53,30 @@ vi.mock('@/store/projectWorkingDirectory', () => ({}));vi.mock('@/hooks/useActiveRouteParams', () => ({ useActiveRouteParams: () => fixture }));vi.mock('@/store/chat', () => ({ useChatStore: () => new Set<string>() }));-vi.mock('@/store/global', () => ({ useGlobalStore: () => vi.fn() }));+vi.mock('@/store/global', () => ({+ useGlobalStore: (selector: (s: unknown) => unknown) => selector({ updateSystemStatus }),+}));vi.mock('i18next', () => ({ t: (key: string) => key }));+const RevealHost = ({ children }: PropsWithChildren) => {+ const [extraRows, setExtraRows] = useState(0);+ return createElement(+ TopicListRevealContext,+ { value: { extraRows, revealMore: () => setExtraRows((rows) => rows + 20) } },+ children,+ );+};const wrapper = ({ children }: PropsWithChildren) =>- createElement(TopicListScopeContext, { value: { projectId: 'project-a' } }, children);+ createElement(+ TopicListScopeContext,+ { value: { projectId: 'project-a' } },+ createElement(RevealHost, null, children),+ );describe('Project topics use the canonical Agent sidebar rules', () => {beforeEach(() => {fixture.topicId = undefined;+ updateSystemStatus.mockClear();});it('pins favorites and orders the rest by the selected timestamp across Agents', () => {const { result, rerender } = renderHook(@@ -106,4 +122,23 @@ describe('Project topics use the canonical Agent sidebar rules', () => {expect(result.current.topics.map((topic) => topic.id)).toEqual(['star']);expect(result.current.hasMore).toBe(true);});+ // Growing the global `topicPageSize` past the server's `getTopics` cap of+ // 100 made every Agent's topic list fail validation, so "load more" in a+ // project only reveals more of the already-loaded rows.+ it('loads more project topics without growing the global topic page size', () => {+ // The list and the collapse-all toggle each call the hook; both must see+ // the revealed rows.+ const { result } = renderHook(+ () => ({+ list: useScopedSidebarTopics(1, 'updatedAt', 'byAgent', false),+ toggle: useScopedSidebarTopics(1, 'updatedAt', 'byAgent', false),+ }),+ { wrapper },+ );+ act(() => result.current.list.loadMore());+ expect(result.current.list.topics.map((topic) => topic.id)).toEqual(['star', 'old', 'new']);+ expect(result.current.list.hasMore).toBe(false);+ expect(result.current.toggle.groups).toEqual(result.current.list.groups);+ expect(updateSystemStatus).not.toHaveBeenCalled();+ });});diff --git a/src/features/AgentSidebar/Topic/useScopedTopics.ts b/src/features/AgentSidebar/Topic/useScopedTopics.tsindex c3cc8640d0d..8d2895d94b4 100644--- a/src/features/AgentSidebar/Topic/useScopedTopics.ts+++ b/src/features/AgentSidebar/Topic/useScopedTopics.ts@@ -5,11 +5,10 @@ import { useActiveRouteParams } from '@/hooks/useActiveRouteParams';import { useChatStore } from '@/store/chat';import { operationSelectors } from '@/store/chat/selectors';import { groupSidebarTopics, selectSidebarTopics } from '@/store/chat/slices/topic/selectors';-import { useGlobalStore } from '@/store/global';import { useProjectDirectoryStore, useProjectTopics } from '@/store/projectWorkingDirectory';import type { ChatTopic, TopicGroupMode, TopicSortBy } from '@/types/topic';-import { useTopicListScope } from './TopicListScope';+import { useTopicListReveal, useTopicListScope } from './TopicListScope';export const useScopedTopics = () => {const scope = useTopicListScope();@@ -41,7 +40,10 @@ export const useScopedSidebarTopics = () => {const { scope, topics } = useScopedTopics();const { topicId } = useActiveRouteParams<{ topicId?: string }>();- const updateSystemStatus = useGlobalStore((s) => s.updateSystemStatus);+ // Project topics are already loaded in full, so "load more" only reveals more+ // rows through host-owned state (see `TopicListRevealContext`).+ const reveal = useTopicListReveal();+ const visibleLimit = pageSize + (reveal?.extraRows ?? 0);const running = useChatStore(operationSelectors.visiblyRunningTopicIds);const visible = useMemo(() => {const list: ChatTopic[] = (topics ?? []).filter(@@ -49,12 +51,12 @@ export const useScopedSidebarTopics = ();return selectSidebarTopics(list,- pageSize,+ visibleLimit,sortBy,includeCompleted,list.find((topic) => topic.id === topicId),);- }, [topics, topicId, pageSize, sortBy, includeCompleted]);+ }, [topics, topicId, visibleLimit, sortBy, includeCompleted]);const groups = useMemo(() => groupSidebarTopics(visible, groupMode, sortBy, running),[visible, groupMode, sortBy, running],@@ -64,13 +66,13 @@ export const useScopedSidebarTopics = ((topic) =>(!topic.trigger || !MAIN_SIDEBAR_EXCLUDE_TRIGGERS.includes(topic.trigger)) &&(includeCompleted || topic.status !== 'completed'),- ).length > pageSize;+ ).length > visibleLimit;return {scope,topics: visible,groups,activeTopicId: topicId,hasMore,- loadMore: () => updateSystemStatus({ topicPageSize: pageSize + 20 }),+ loadMore: () => reveal?.revealMore(),};};diff --git a/src/features/Projects/WorkingDirectories/SidebarTopics.tsx b/src/features/Projects/WorkingDirectories/SidebarTopics.tsxindex 95e70602b4e..acac1538054 100644--- a/src/features/Projects/WorkingDirectories/SidebarTopics.tsx+++ b/src/features/Projects/WorkingDirectories/SidebarTopics.tsx@@ -13,7 +13,10 @@ import ByProjectMode from '@/features/AgentSidebar/Topic/TopicListContent/ByProjimport ByStatusMode from '@/features/AgentSidebar/Topic/TopicListContent/ByStatusMode';import ByTimeMode from '@/features/AgentSidebar/Topic/TopicListContent/ByTimeMode';import FlatMode from '@/features/AgentSidebar/Topic/TopicListContent/FlatMode';-import { TopicListScopeContext } from '@/features/AgentSidebar/Topic/TopicListScope';+import {+ TopicListRevealContext,+ TopicListScopeContext,+} from '@/features/AgentSidebar/Topic/TopicListScope';import SkeletonList from '@/features/NavPanel/components/SkeletonList';import {useProjectDirectories,@@ -22,12 +25,16 @@ import {} from '@/store/projectWorkingDirectory';import { openProjectTopicModal } from './StartDirectoryModal';+import { useProjectTopicReveal } from './useProjectTopicReveal';export function ProjectDirectoryTopics(props: { projectId: string; coordinatorAgentId: string }) {const scope = useMemo(() => ({ projectId: props.projectId }), [props.projectId]);+ const reveal = useProjectTopicReveal(props.projectId);return (<TopicListScopeContext value={scope}>- <ProjectTopicList {...props} />+ <TopicListRevealContext value={reveal}>+ <ProjectTopicList {...props} />+ </TopicListRevealContext></TopicListScopeContext>);}diff --git a/src/features/Projects/WorkingDirectories/useProjectTopicReveal.test.ts b/src/features/Projects/WorkingDirectories/useProjectTopicReveal.test.tsnew file mode 100644index 00000000000..3224703ca83--- /dev/null+++ b/src/features/Projects/WorkingDirectories/useProjectTopicReveal.test.ts@@ -0,0 +1,32 @@+import { act, renderHook } from '@testing-library/react';+import { describe, expect, it } from 'vitest';++import { useProjectTopicReveal } from './useProjectTopicReveal';++describe('useProjectTopicReveal', () => {+ it('reveals more rows on each call', () => {+ const { result } = renderHook(() => useProjectTopicReveal('project-a'));++ act(() => result.current.revealMore());+ act(() => result.current.revealMore());++ expect(result.current.extraRows).toBe(40);+ });++ // The sidebar stays mounted across project switches, so returning to a+ // project used to restore its old expansion instead of the first page.+ it('starts from the first page again after switching away and back', () => {+ const { result, rerender } = renderHook(({ id }) => useProjectTopicReveal(id), {+ initialProps: { id: 'project-a' },+ });++ act(() => result.current.revealMore());+ expect(result.current.extraRows).toBe(20);++ rerender({ id: 'project-b' });+ expect(result.current.extraRows).toBe(0);++ rerender({ id: 'project-a' });+ expect(result.current.extraRows).toBe(0);+ });+});diff --git a/src/features/Projects/WorkingDirectories/useProjectTopicReveal.ts b/src/features/Projects/WorkingDirectories/useProjectTopicReveal.tsnew file mode 100644index 00000000000..607907ef4e8--- /dev/null+++ b/src/features/Projects/WorkingDirectories/useProjectTopicReveal.ts@@ -0,0 +1,27 @@+import { useCallback, useMemo, useState } from 'react';++import { type TopicListRevealState } from '@/features/AgentSidebar/Topic/TopicListScope';++/** Rows each "View all" click reveals beyond the shared `topicPageSize`. */+const REVEAL_STEP = 20;++/**+ * Rows the Project sidebar has revealed for `projectId`.+ *+ * The sidebar stays mounted under the persistent project layout, so the+ * expansion resets on every project change. Keying it by id alone would let a+ * return to project A (A β B β A) restore A's old expansion.+ */+export const useProjectTopicReveal = (projectId: string): TopicListRevealState => {+ const [revealed, setRevealed] = useState({ projectId, rows: 0 });+ // Adjust state while rendering on a prop change, so the reset lands before paint.+ if (revealed.projectId !== projectId) setRevealed({ projectId, rows: 0 });++ const extraRows = revealed.projectId === projectId ? revealed.rows : 0;+ const revealMore = useCallback(+ () => setRevealed({ projectId, rows: extraRows + REVEAL_STEP }),+ [projectId, extraRows],+ );++ return useMemo(() => ({ extraRows, revealMore }), [extraRows, revealMore]);+};diff --git a/src/store/global/selectors/systemStatus.test.ts b/src/store/global/selectors/systemStatus.test.tsindex 3ade08ee045..1c640505b64 100644--- a/src/store/global/selectors/systemStatus.test.ts+++ b/src/store/global/selectors/systemStatus.test.ts@@ -138,6 +138,19 @@ describe('systemStatusSelectors', () => {});});+ describe('topicPageSize', () => {+ it('defaults to 20', () => {+ expect(systemStatusSelectors.topicPageSize(initialState)).toBe(20);+ });++ // A value above the server's `getTopics` cap failed every topic list+ // request; earlier builds could persist one from the project sidebar.+ it('clamps a persisted value above the server cap', () => {+ const s: GlobalState = merge(initialState, { status: { topicPageSize: 140 } });+ expect(systemStatusSelectors.topicPageSize(s)).toBe(100);+ });+ });+describe('modelDetailPanelExpandedKeys', () => {it('should expand every section by default', () => {const s: GlobalState = {diff --git a/src/store/global/selectors/systemStatus.ts b/src/store/global/selectors/systemStatus.tsindex 1e2f3705b47..85fe268e812 100644--- a/src/store/global/selectors/systemStatus.ts+++ b/src/store/global/selectors/systemStatus.ts@@ -95,7 +95,16 @@ const agentSidebarSections =(s: GlobalState): Record<string, boolean> | undefined =>agentId ? s.status.expandAgentSidebarSectionsByAgent?.[agentId] : undefined;-const topicPageSize = (s: GlobalState): number => s.status.topicPageSize || 20;+/** Upper bound of `topic.getTopics`'s `pageSize` input on the server. */+export const MAX_TOPIC_PAGE_SIZE = 100;++/**+ * Clamped to the server's cap: the project sidebar's "load more" used to grow+ * the persisted value past 100, after which every topic list request failed+ * validation. Clamping on read recovers users who already persisted it.+ */+const topicPageSize = (s: GlobalState): number =>+ Math.min(s.status.topicPageSize || 20, MAX_TOPIC_PAGE_SIZE);const agentPageSize = (s: GlobalState): number => s.status.agentPageSize || 5;