🤯 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: correct home sidebar spacing and scroll fade (#21949)
AmAzing-7e82d1ddc54a
diff --git a/src/features/HomeSidebar/Body/index.test.tsx b/src/features/HomeSidebar/Body/index.test.tsxindex b72119f06f1..e6810cff918 100644--- a/src/features/HomeSidebar/Body/index.test.tsx+++ b/src/features/HomeSidebar/Body/index.test.tsx@@ -26,8 +26,8 @@ vi.mock('@lobehub/ui', async (importOriginal) => {const factories: ((original: typeof importOriginal) => unknown)[] = [async (importOriginal) => ({...(await importOriginal<object>()),- Flexbox: ({ children }: { children: React.ReactNode }) => (- <div data-testid="sidebar-body">{children}</div>+ Flexbox: ({ children, flex }: { children: React.ReactNode; flex?: number }) => (+ <div data-testid={flex ? 'sidebar-body' : 'sidebar-sections'}>{children}</div>),}),async (importOriginal) => ({@@ -171,13 +171,13 @@ describe('Home sidebar body', () => {child.hasAttribute('data-sidebar-bottom-spacer'),);- expect(spacerIndex).toBe(3);+ expect(spacerIndex).toBe(2);expect(children[0]).toHaveTextContent('Pages');- expect(children[1]).toHaveAttribute('data-testid', 'sidebar-accordion');- expect(children[2]).toHaveAttribute('data-testid', 'sidebar-channels');- expect(children[4]).toHaveTextContent('Image');- expect(children[5]).toHaveTextContent('Tasks');- expect(children[6]).toHaveTextContent('Resource');+ expect(children[1]).toContainElement(screen.getByTestId('sidebar-item-agent'));+ expect(children[1]).toContainElement(screen.getByTestId('sidebar-channels'));+ expect(children[3]).toHaveTextContent('Image');+ expect(children[4]).toHaveTextContent('Tasks');+ expect(children[5]).toHaveTextContent('Resource');});it('keeps a top item that was dragged past the spacer in its new position', () => {@@ -192,19 +192,19 @@ describe('Home sidebar body', () => {const children = Array.from(screen.getByTestId('sidebar-body').children);- expect(children[0]).toHaveAttribute('data-testid', 'sidebar-accordion');- expect(children[1]).toHaveAttribute('data-testid', 'sidebar-channels');- expect(children[2]).toHaveAttribute('data-sidebar-bottom-spacer');- expect(children[3]).toHaveTextContent('Image');- expect(children[4]).toHaveTextContent('Tasks');+ expect(children[0]).toContainElement(screen.getByTestId('sidebar-item-agent'));+ expect(children[0]).toContainElement(screen.getByTestId('sidebar-channels'));+ expect(children[1]).toHaveAttribute('data-sidebar-bottom-spacer');+ expect(children[2]).toHaveTextContent('Image');+ expect(children[3]).toHaveTextContent('Tasks');});- it('places Channels directly below Agents, outside the Agent accordion', () => {+ it('keeps Channels between adjacent sections in the same spacing group with its own accordion', () => {mocks.globalState.status.sidebarItems = ['agent', 'recents'];render(<Body />);- const children = Array.from(screen.getByTestId('sidebar-body').children);+ const children = Array.from(screen.getByTestId('sidebar-sections').children);expect(children[0]).toContainElement(screen.getByTestId('sidebar-item-agent'));expect(children[1]).toHaveAttribute('data-testid', 'sidebar-channels');diff --git a/src/features/HomeSidebar/Body/index.tsx b/src/features/HomeSidebar/Body/index.tsxindex b93dbbdbe79..d8b91bb2345 100644--- a/src/features/HomeSidebar/Body/index.tsx+++ b/src/features/HomeSidebar/Body/index.tsx@@ -53,6 +53,7 @@ const ACCORDION_KEYS = new Set<string>([/** Keys rendered in the header — must be excluded from the body to avoid duplicates* when migrating users whose persisted sidebarItems still include them. */const HEADER_KEYS = new Set<string>(['home', 'search']);+const SECTION_GAP = 8;const accordionComponents: Record<string, (key: string) => ReactElement> = {[GroupKey.Agent]: (key) => <Agent itemKey={key} key={key} />,@@ -204,22 +205,22 @@ const Body = memo(() => {[sidebarExpandedKeys, updateSystemStatus],);- // Render the flat list in `sidebarItems` order: group consecutive accordion- // items into an Accordion, interleave non-accordion keys as nav links, and- // emit a flex spacer wherever the spacer sentinel appears.+ // Consecutive sections share one spacing group, including Channels' independent+ // accordion. Nav links and the spacer keep their positions and compact spacing.const content = useMemo(() => {const elements: ReactElement[] = [];let accGroup: { element: ReactElement; key: string }[] = [];+ let sectionGroup: ReactElement[] = [];const flushAccordion = () => {if (accGroup.length > 0) {const accordionKeys = accGroup.map((item) => item.key);- elements.push(+ sectionGroup.push(<AccordionRootindicatorPlacement="inline"- key={`acc-${elements.length}`}- style={{ gap: 8 }}+ key={`acc-${sectionGroup.length}`}+ style={{ gap: SECTION_GAP }}value={sidebarExpandedKeys}onValueChange={(keys) => handleAccordionExpandedChange(accordionKeys, keys as string[])}>@@ -230,9 +231,21 @@ const Body = memo(() => {}};+ const flushSections = () => {+ flushAccordion();+ if (sectionGroup.length > 0) {+ elements.push(+ <Flexbox gap={SECTION_GAP} key={`sections-${elements.length}`}>+ {sectionGroup}+ </Flexbox>,+ );+ sectionGroup = [];+ }+ };+for (const key of visibleKeys) {if (key === SIDEBAR_SPACER_ID) {- flushAccordion();+ flushSections();elements.push(<divaria-hidden@@ -247,15 +260,17 @@ const Body = memo(() => {// Channels sit right below Agents, in their own accordion.if (key === GroupKey.Agent) {flushAccordion();- elements.push(<ChannelList key="channels" />);+ sectionGroup.push(<ChannelList key="channels" />);}} else {- flushAccordion();const link = renderNavLink(key);- if (link) elements.push(link);+ if (link) {+ flushSections();+ elements.push(link);+ }}}- flushAccordion();+ flushSections();return elements;}, [visibleKeys, renderNavLink, sidebarExpandedKeys, handleAccordionExpandedChange]);diff --git a/src/features/HomeSidebar/Content.tsx b/src/features/HomeSidebar/Content.tsxindex 28cec9e16bf..dc8e506eb03 100644--- a/src/features/HomeSidebar/Content.tsx+++ b/src/features/HomeSidebar/Content.tsx@@ -7,7 +7,18 @@ import Header from './Header';const HomeSidebarContent = () => {return (<AgentModalProvider>- <SideBarLayout body={<Body />} header={<Header />} />+ <SideBarLayout+ body={<Body />}+ header={<Header />}+ // Let ScrollArea observe accordion height changes and update its overflow fade.+ // The minimum height and flex layout keep the bottom spacer working.+ contentStyle={{+ display: 'flex',+ flexDirection: 'column',+ height: 'auto',+ minHeight: '100%',+ }}+ /></AgentModalProvider>);};diff --git a/src/features/NavPanel/SideBarLayout.tsx b/src/features/NavPanel/SideBarLayout.tsxindex b358fc17a2f..9c89df626b1 100644--- a/src/features/NavPanel/SideBarLayout.tsx+++ b/src/features/NavPanel/SideBarLayout.tsx@@ -1,5 +1,5 @@import { Flexbox, ScrollArea, TooltipGroup } from '@lobehub/ui';-import { type ReactNode, type UIEvent } from 'react';+import { type CSSProperties, type ReactNode, type UIEvent } from 'react';import { memo, Suspense, useCallback, useLayoutEffect, useRef } from 'react';import { SideBarHeaderSkeleton } from '@/features/NavPanel/components/SideBarSkeleton';@@ -11,10 +11,11 @@ const scrollOffsets = new Map<string, number>();interface SidebarLayoutProps {body?: ReactNode;+ contentStyle?: CSSProperties;header?: ReactNode;}-const SideBarLayout = memo<SidebarLayoutProps>(({ header, body }) => {+const SideBarLayout = memo<SidebarLayoutProps>(({ header, body, contentStyle }) => {const navKey = useActiveNavKey();const scrollerRef = useRef<HTMLDivElement>(null);@@ -38,7 +39,7 @@ const SideBarLayout = memo<SidebarLayoutProps>(({ header, body }) => {disableContentFitscrollFade// Preserve the height chain for sidebar bodies containing virtual lists.- contentProps={{ style: { height: '100%' } }}+ contentProps={{ style: { height: '100%', ...contentStyle } }}style={{ flex: 1, minHeight: 0 }}viewportProps={{ onScroll: handleScroll, ref: scrollerRef }}>