π€― 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(nav-panel): keep the Home sidebar on routes without a dedicated panel (#17718)
Inneid8fc25ac3def
diff --git a/src/features/HomeSidebar/Content.tsx b/src/features/HomeSidebar/Content.tsxnew file mode 100644index 00000000000..3630619c1fd--- /dev/null+++ b/src/features/HomeSidebar/Content.tsx@@ -0,0 +1,18 @@+import { memo } from 'react';++import SideBarLayout from '@/features/NavPanel/SideBarLayout';+import Body from '@/routes/(main)/home/_layout/Body';+import { AgentModalProvider } from '@/routes/(main)/home/_layout/Body/Agent/ModalProvider';+import Header from '@/routes/(main)/home/_layout/Header';++const HomeSidebarContent = memo(() => {+ return (+ <AgentModalProvider>+ <SideBarLayout body={<Body />} header={<Header />} />+ </AgentModalProvider>+ );+});++HomeSidebarContent.displayName = 'HomeSidebarContent';++export default HomeSidebarContent;diff --git a/src/features/HomeSidebar/index.tsx b/src/features/HomeSidebar/index.tsxnew file mode 100644index 00000000000..6ba30185468--- /dev/null+++ b/src/features/HomeSidebar/index.tsx@@ -0,0 +1,15 @@+import { memo } from 'react';++import { NavPanelPortal } from '@/features/NavPanel/NavPanelPortal';++import HomeSidebarContent from './Content';++const HomeNavPanelPortal = memo(() => (+ <NavPanelPortal navKey="home">+ <HomeSidebarContent />+ </NavPanelPortal>+));++HomeNavPanelPortal.displayName = 'HomeNavPanelPortal';++export default HomeNavPanelPortal;diff --git a/src/features/NavPanel/Shell.tsx b/src/features/NavPanel/Shell.tsxnew file mode 100644index 00000000000..3ad50138d30--- /dev/null+++ b/src/features/NavPanel/Shell.tsx@@ -0,0 +1,24 @@+'use client';++import { memo } from 'react';++import HomeNavPanelPortal from '@/features/HomeSidebar';++import NavPanel from './index';++// The Home portal is owned by the shell, not by the Home route layout: routes+// without a dedicated sidebar (for example /tasks, /agents) resolve to the+// `home` nav key, and on desktop `NavPanel` lives outside `TabHost` while the+// Home layout only mounts inside a home tab β and `Activity` unmounts effects+// for inactive tabs. Registering from the route layout leaves those tabs with+// no `home` entry at all, so the panel is stuck on the loading skeleton.+const NavPanelShell = memo(() => (+ <>+ <HomeNavPanelPortal />+ <NavPanel />+ </>+));++NavPanelShell.displayName = 'NavPanelShell';++export default NavPanelShell;diff --git a/src/features/NavPanel/index.test.tsx b/src/features/NavPanel/index.test.tsxindex 210f3fb7fb7..84f98144a27 100644--- a/src/features/NavPanel/index.test.tsx+++ b/src/features/NavPanel/index.test.tsx@@ -5,6 +5,7 @@ import { beforeEach, describe, expect, it, vi } from 'vitest';import NavPanel from './index';import { NavPanelPortal } from './NavPanelPortal';import { clearNavPanelRegistry } from './registry';+import NavPanelShell from './Shell';let pathname = '/lobe-team/settings/general';@@ -47,6 +48,10 @@ vi.mock('./components/SkeletonList', () => ({default: () => <div>Nav panel loading</div>,}));+vi.mock('@/features/HomeSidebar/Content', () => ({+ default: () => <div>Home sidebar</div>,+}));+describe('NavPanel', () => {beforeEach(() => {pathname = '/lobe-team/settings/general';@@ -140,3 +145,32 @@ describe('NavPanel', () => {expect(screen.queryByText('Nav panel loading')).not.toBeInTheDocument();});});++describe('NavPanelShell', () => {+ beforeEach(() => {+ clearNavPanelRegistry();+ });++ it('provides the Home entry on routes that never mount the Home layout', async () => {+ pathname = '/tasks';++ render(<NavPanelShell />);++ await waitFor(() => {+ expect(screen.getByText('Home sidebar')).toBeInTheDocument();+ });+ expect(screen.getByTestId('nav-panel')).toHaveAttribute('data-nav-key', 'home');+ expect(screen.queryByText('Nav panel loading')).not.toBeInTheDocument();+ });++ it('still yields to a dedicated route panel', async () => {+ pathname = '/community';++ render(<NavPanelShell />);++ await waitFor(() => {+ expect(screen.getByText('Nav panel loading')).toBeInTheDocument();+ });+ expect(screen.queryByText('Home sidebar')).not.toBeInTheDocument();+ });+});diff --git a/src/routes/(main)/_layout/index.desktop.tsx b/src/routes/(main)/_layout/index.desktop.tsxindex c37a6f96e6c..ce84f487cba 100644--- a/src/routes/(main)/_layout/index.desktop.tsx+++ b/src/routes/(main)/_layout/index.desktop.tsx@@ -23,7 +23,7 @@ import { TabHost, useSeedTabsOnBoot } from '@/features/Electron/TabHost';import TabCacheBridges from '@/features/Electron/titlebar/TabBar/TabCacheBridges';import TitleBar from '@/features/Electron/titlebar/TitleBar';import HotkeyHelperPanel from '@/features/HotkeyHelperPanel';-import NavPanel from '@/features/NavPanel';+import NavPanelShell from '@/features/NavPanel/Shell';import { usePlatform } from '@/hooks/usePlatform';import CmdkLazy from '@/layout/GlobalProvider/CmdkLazy';import dynamic from '@/libs/next/dynamic';@@ -76,7 +76,7 @@ const Layout: FC = () => {height={`calc(100% - ${TITLE_BAR_HEIGHT}px)`}width={'100%'}>- <NavPanel />+ <NavPanelShell /><DesktopLayoutContainer><Flexbox height={'100%'} style={tabHostContainer} width={'100%'}><TabHost />diff --git a/src/routes/(main)/_layout/index.tsx b/src/routes/(main)/_layout/index.tsxindex faf81628bc5..09f98471a2b 100644--- a/src/routes/(main)/_layout/index.tsx+++ b/src/routes/(main)/_layout/index.tsx@@ -24,7 +24,7 @@ import ZoomHUD from '@/features/Electron/system/ZoomHUD';import TabCacheBridges from '@/features/Electron/titlebar/TabBar/TabCacheBridges';import TitleBar from '@/features/Electron/titlebar/TitleBar';import HotkeyHelperPanel from '@/features/HotkeyHelperPanel';-import NavPanel from '@/features/NavPanel';+import NavPanelShell from '@/features/NavPanel/Shell';import { RouteMetaBridge } from '@/features/RouteMeta';import { usePlatform } from '@/hooks/usePlatform';import CmdkLazy from '@/layout/GlobalProvider/CmdkLazy';@@ -78,7 +78,7 @@ const Layout: FC = () => {: '100%'}>- <NavPanel />+ <NavPanelShell /><DesktopLayoutContainer><DesktopHomeLayout><DesktopHome />diff --git a/src/routes/(main)/home/_layout/Sidebar.tsx b/src/routes/(main)/home/_layout/Sidebar.tsxdeleted file mode 100644index 4a5a24559b7..00000000000--- a/src/routes/(main)/home/_layout/Sidebar.tsx+++ /dev/null@@ -1,16 +0,0 @@-import { memo } from 'react';--import { NavPanelPortal } from '@/features/NavPanel/NavPanelPortal';--import SidebarContent from './SidebarContent';--// Home stays registered while React Activity keeps its layout alive. NavPanelHost-// selects content by pathname, so a Home update can no longer overwrite the-// currently active route's entry.-const Sidebar = memo(() => (- <NavPanelPortal navKey="home">- <SidebarContent />- </NavPanelPortal>-));--export default Sidebar;diff --git a/src/routes/(main)/home/_layout/SidebarContent.tsx b/src/routes/(main)/home/_layout/SidebarContent.tsxdeleted file mode 100644index 7b08b2631bd..00000000000--- a/src/routes/(main)/home/_layout/SidebarContent.tsx+++ /dev/null@@ -1,17 +0,0 @@-import { memo } from 'react';--import SideBarLayout from '@/features/NavPanel/SideBarLayout';--import Body from './Body';-import { AgentModalProvider } from './Body/Agent/ModalProvider';-import Header from './Header';--const Sidebar = memo(() => {- return (- <AgentModalProvider>- <SideBarLayout body={<Body />} header={<Header />} />- </AgentModalProvider>- );-});--export default Sidebar;diff --git a/src/routes/(main)/home/_layout/index.tsx b/src/routes/(main)/home/_layout/index.tsxindex 68e860b9d44..019e896c649 100644--- a/src/routes/(main)/home/_layout/index.tsx+++ b/src/routes/(main)/home/_layout/index.tsx@@ -8,7 +8,6 @@ import { useIsDark } from '@/hooks/useIsDark';import HomeAgentIdSync from './HomeAgentIdSync';import RecentHydration from './RecentHydration';-import Sidebar from './Sidebar';import { styles } from './style';interface LayoutProps {@@ -38,39 +37,34 @@ const Layout: FC<LayoutProps> = ({ children }) => {[theme.colorBgContainerSecondary],);- // Register the Home sidebar even on a cold deep link. Routes without a- // dedicated sidebar (for example /tasks) intentionally use the Home entry.- if (!hasActivated) return <Sidebar />;+ if (!hasActivated) return null;- // Keep the Home layout alive and render it offscreen when inactive. The- // Portal stays outside Activity so its registry entry remains available to- // routes that intentionally reuse Home navigation (for example /tasks).+ // Keep the Home layout alive and render it offscreen when inactive. The nav+ // panel entry is owned by `NavPanelShell`, not by this layout β see the note+ // there for why it cannot be registered from inside the route tree.return (- <>- <Sidebar />- <Activity mode={isHomeRoute ? 'visible' : 'hidden'} name="DesktopHomeLayout">- {/* `position: absolute; inset: 0` keeps overlaying the outlet when Activity is hidden,+ <Activity mode={isHomeRoute ? 'visible' : 'hidden'} name="DesktopHomeLayout">+ {/* `position: absolute; inset: 0` keeps overlaying the outlet when Activity is hidden,because Activity preserves state but doesn't visually hide the DOM. Force-hide here. */}+ <Flexbox+ className={styles.absoluteContainer}+ height={'100%'}+ style={isHomeRoute ? undefined : { display: 'none' }}+ width={'100%'}+ ><Flexbox- className={styles.absoluteContainer}+ className={isDarkMode ? styles.contentDark : styles.contentLight}+ flex={1}height={'100%'}- style={isHomeRoute ? undefined : { display: 'none' }}- width={'100%'}+ style={cssVariables}>- <Flexbox- className={isDarkMode ? styles.contentDark : styles.contentLight}- flex={1}- height={'100%'}- style={cssVariables}- >- {content}- </Flexbox>-- <HomeAgentIdSync />- <RecentHydration />+ {content}</Flexbox>- </Activity>- </>++ <HomeAgentIdSync />+ <RecentHydration />+ </Flexbox>+ </Activity>);};