π€― 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(mobile): restore workspace home and navigation (#21425)
Tsuki64cced00d465
diff --git a/src/hooks/useMobileNavigation.test.ts b/src/hooks/useMobileNavigation.test.tsnew file mode 100644index 00000000000..9cd3f6600b5--- /dev/null+++ b/src/hooks/useMobileNavigation.test.ts@@ -0,0 +1,48 @@+import { renderHook } from '@testing-library/react';+import type { PropsWithChildren } from 'react';+import { createElement } from 'react';+import { createMemoryRouter, RouterProvider } from 'react-router';+import { describe, expect, it } from 'vitest';++import { useMobileNavigation } from './useMobileNavigation';++describe('useMobileNavigation', () => {+ it.each([+ ['/', true, 'chat'],+ ['/community', true, 'community'],+ ['/me', true, 'me'],+ ['/agent/agt_fixture', false, 'agent'],+ ['/acme', true, 'chat'],+ ['/acme/', true, 'chat'],+ ['/acme/community', true, 'community'],+ ['/acme/community/agent', true, 'community'],+ ['/acme/community/agent/', true, 'community'],+ ['/acme/community/agent/agt_fixture', false, 'community'],+ ['/acme/agent/agt_fixture', false, 'agent'],+ ['/acme/settings/general', false, 'settings'],+ ])('resolves navigation for %s', (pathname, showNav, activeKey) => {+ const wrapper = ({ children }: PropsWithChildren) =>+ createElement(RouterProvider, {+ router: createMemoryRouter(+ [+ {+ children: [+ { index: true },+ { path: 'agent/*' },+ { path: 'community/*' },+ { path: 'me/*' },+ { path: ':workspaceSlug/*' },+ ],+ element: children,+ path: '/',+ },+ ],+ { initialEntries: [pathname] },+ ),+ });++ const { result } = renderHook(useMobileNavigation, { wrapper });++ expect(result.current).toEqual({ activeKey, showNav });+ });+});diff --git a/src/hooks/useMobileNavigation.ts b/src/hooks/useMobileNavigation.tsnew file mode 100644index 00000000000..b71faeba85e--- /dev/null+++ b/src/hooks/useMobileNavigation.ts@@ -0,0 +1,26 @@+import { useLocation, useParams } from 'react-router';++import { SidebarTabKey } from '@/store/global/initialState';++const MOBILE_NAV_ROUTES = new Set([+ '/',+ '/community',+ '/community/agent',+ '/community/mcp',+ '/community/plugin',+ '/community/model',+ '/community/provider',+ '/me',+]);++/** Resolve navigation against the page within the matched workspace, not its slug. */+export const useMobileNavigation = () => {+ const { pathname } = useLocation();+ const { workspaceSlug } = useParams<{ workspaceSlug: string }>();+ const pagePathname = workspaceSlug ? pathname.slice(workspaceSlug.length + 1) || '/' : pathname;+ const normalizedPathname = pagePathname.replace(/\/+$/, '') || '/';+ const activeKey =+ (normalizedPathname.split('/').find(Boolean) as SidebarTabKey) || SidebarTabKey.Chat;++ return { activeKey, showNav: MOBILE_NAV_ROUTES.has(normalizedPathname) };+};diff --git a/src/routes/(mobile)/_layout/NavBar.tsx b/src/routes/(mobile)/_layout/NavBar.tsxindex 712781021a8..f777affa927 100644--- a/src/routes/(mobile)/_layout/NavBar.tsx+++ b/src/routes/(mobile)/_layout/NavBar.tsx@@ -9,7 +9,7 @@ import { useTranslation } from 'react-i18next';import { MOBILE_TABBAR_HEIGHT } from '@/const/layoutTokens';import { useWorkspaceAwareNavigate } from '@/features/Workspace/useWorkspaceAwareNavigate';-import { useActiveTabKey } from '@/hooks/useActiveTabKey';+import { useMobileNavigation } from '@/hooks/useMobileNavigation';import { SidebarTabKey } from '@/store/global/initialState';import { featureFlagsSelectors, useServerConfigStore } from '@/store/serverConfig';@@ -29,7 +29,7 @@ const styles = createStaticStyles(({ css, cssVar }) => ({const NavBar = memo(() => {const { t } = useTranslation('common');- const activeKey = useActiveTabKey();+ const { activeKey } = useMobileNavigation();const navigate = useWorkspaceAwareNavigate();const { showMarket } = useServerConfigStore(featureFlagsSelectors);@@ -68,7 +68,7 @@ const NavBar = memo(() => {title: t('tab.me'),},].filter(Boolean) as TabBarProps['items'],- [t],+ [navigate, showMarket, t],);return (diff --git a/src/routes/(mobile)/_layout/index.tsx b/src/routes/(mobile)/_layout/index.tsxindex d3e47a566cf..c23725e7ba5 100644--- a/src/routes/(mobile)/_layout/index.tsx+++ b/src/routes/(mobile)/_layout/index.tsx@@ -2,33 +2,22 @@import { type FC } from 'react';import { Suspense } from 'react';-import { Outlet, useLocation } from 'react-router';+import { Outlet } from 'react-router';import WorkspaceContextSlot from '@/business/client/WorkspaceContextSlot';import Loading from '@/components/Loading/BrandTextLoading';import { RouteMetaBridge } from '@/features/RouteMeta';+import { useMobileNavigation } from '@/hooks/useMobileNavigation';import dynamic from '@/libs/next/dynamic';import { featureFlagsSelectors, useServerConfigStore } from '@/store/serverConfig';import NavBar from './NavBar';const CloudBanner = dynamic(() => import('@/features/AlertBanner/CloudBanner'));-const MOBILE_NAV_ROUTES = new Set([- '/',- '/community',- '/community/agent',- '/community/mcp',- '/community/plugin',- '/community/model',- '/community/provider',- '/me',-]);const MobileMainLayout: FC = () => {const { showCloudPromotion } = useServerConfigStore(featureFlagsSelectors);- const location = useLocation();- const pathname = location.pathname;- const showNav = MOBILE_NAV_ROUTES.has(pathname);+ const { showNav } = useMobileNavigation();return (<WorkspaceContextSlot><RouteMetaBridge />diff --git a/src/spa/router/mobileRouter.config.tsx b/src/spa/router/mobileRouter.config.tsxindex 6a6e4431dee..fdb2b9812f2 100644--- a/src/spa/router/mobileRouter.config.tsx+++ b/src/spa/router/mobileRouter.config.tsx@@ -27,10 +27,27 @@ const mobileChatElement = dynamicElement({ preloadId: 'mobile-agent' },);+// Mobile owns its home layout; it has no persistent desktop Home outside the outlet.+const mobileHomeRoute: RouteObject = {+ children: [+ {+ element: dynamicElement(() => import('@/routes/(mobile)/(home)/'), 'Mobile > Home', {+ preloadId: 'mobile-home',+ }),+ index: true,+ },+ ],+ element: dynamicLayout(+ () => import('@/routes/(mobile)/(home)/_layout'),+ 'Mobile > Home > Layout',+ { preloadId: 'mobile-home' },+ ),+ handle: { meta: routeMeta({ Skeleton: createSurfaceSkeleton('list') }) },+};+/*** Children shared between `/` and `/:workspaceSlug` for mobile. Mobile only- * mirrors the subset of routes it actually supports β settings / me / default- * home stay personal-only.+ * mirrors the subset of routes it actually supports β settings / me stay personal-only.*/export const sharedMainAreaChildren: RouteObject[] = [// Chat routes@@ -481,31 +498,13 @@ export const mobileRoutes: RouteObject[] = [},// Default route - home page- {- children: [- {- element: dynamicElement(() => import('@/routes/(mobile)/(home)/'), 'Mobile > Home', {- preloadId: 'mobile-home',- }),- index: true,- },- ],- element: dynamicLayout(- () => import('@/routes/(mobile)/(home)/_layout'),- 'Mobile > Home > Layout',- { preloadId: 'mobile-home' },- ),- },+ mobileHomeRoute,// Workspace slug routes β `/:workspaceSlug/*` mirrors the shared main area.// Must come AFTER all reserved root paths so they don't shadow e.g. /agent.{children: [- // Workspace home β handled by the persistent home layout (mirrors- // how `/` index is empty); rendering here would duplicate Home.- {- index: true,- },+ mobileHomeRoute,...sharedMainAreaChildren,// Workspace settings β `/:slug/settings/*`. Mobile reuses the mobile// settings chrome (header + content wrapper) for now; a dedicateddiff --git a/src/spa/router/mobileRouter.test.tsx b/src/spa/router/mobileRouter.test.tsxindex f738bbd9090..ed644303b27 100644--- a/src/spa/router/mobileRouter.test.tsx+++ b/src/spa/router/mobileRouter.test.tsx@@ -7,6 +7,31 @@ import { describe, expect, it } from 'vitest';import { mobileRoutes } from './mobileRouter.config';import { getRouteMetaFromHandle } from './routeMeta';+describe('mobileRouter workspace home', () => {+ it.each(['/acme', '/acme/'])(+ 'renders the mobile home page and layout within the workspace boundary at %s',+ (pathname) => {+ const personalMatches = matchRoutes(mobileRoutes, '/')!;+ const workspaceMatches = matchRoutes(mobileRoutes, pathname)!;++ expect(workspaceMatches.some((match) => match.route.path === ':workspaceSlug')).toBe(true);+ expect(workspaceMatches.at(-1)?.params.workspaceSlug).toBe('acme');+ expect(workspaceMatches.at(-1)?.route.element).toBeTruthy();+ expect(workspaceMatches.at(-1)?.route.element).toBe(personalMatches.at(-1)?.route.element);+ expect(workspaceMatches.at(-2)?.route.element).toBe(personalMatches.at(-2)?.route.element);+ },+ );++ it('keeps workspace conversations outside the home layout', () => {+ const homeMatches = matchRoutes(mobileRoutes, '/acme')!;+ const chatMatches = matchRoutes(mobileRoutes, '/acme/agent/agt_fixture')!;+ const homeLayout = homeMatches.at(-2)?.route;++ expect(chatMatches.at(-1)?.params).toMatchObject({ aid: 'agt_fixture', workspaceSlug: 'acme' });+ expect(chatMatches.some((match) => match.route === homeLayout)).toBe(false);+ });+});+describe('mobileRouter agent share route', () => {it('leaves the agent-share visitor surface to the business routes', () => {// Agent sharing runs a visitor's conversation on the creator's account, so