Skip to content

🤯 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.

💄 style(ui): specialize route skeletons via routeMeta (#18540)

Innei8c24f89407e4
diff --git a/src/components/Skeleton/Goal.tsx b/src/components/Skeleton/Goal.tsx
index b53d2e5bcd5..744909b034b 100644
--- a/src/components/Skeleton/Goal.tsx
+++ b/src/components/Skeleton/Goal.tsx
@@ -5,6 +5,7 @@ import { createStaticStyles, cssVar } from 'antd-style';
import NavHeader from '@/features/NavHeader';
import WideScreenContainer from '@/features/WideScreenContainer';
+import type { RouteSkeletonProps } from '@/spa/router/routeMeta';
import SkeletonBar from './Bar';
@@ -16,13 +17,9 @@ const styles = createStaticStyles(({ css }) => ({
`,
}));
-interface GoalSkeletonProps {
- showHeader?: boolean;
-}
-
-const GoalSkeleton = ({ showHeader = true }: GoalSkeletonProps) => (
+const GoalSkeleton = ({ chrome = 'page' }: RouteSkeletonProps) => (
<Flexbox aria-busy flex={1} height={'100%'}>
- {showHeader && <NavHeader />}
+ {chrome !== 'body' && <NavHeader />}
<WideScreenContainer
flex={1}
gap={20}
diff --git a/src/components/Skeleton/GoalDetail.tsx b/src/components/Skeleton/GoalDetail.tsx
index 6a11964fe5a..8620f6e8018 100644
--- a/src/components/Skeleton/GoalDetail.tsx
+++ b/src/components/Skeleton/GoalDetail.tsx
@@ -5,13 +5,10 @@ import { cssVar } from 'antd-style';
import NavHeader from '@/features/NavHeader';
import WideScreenContainer from '@/features/WideScreenContainer';
+import type { RouteSkeletonProps } from '@/spa/router/routeMeta';
import SkeletonBar from './Bar';
-interface GoalDetailSkeletonProps {
- showHeader?: boolean;
-}
-
const GoalDetailContentSkeleton = () => (
<Flexbox aria-busy gap={20} paddingBlock={8}>
<Flexbox gap={10}>
@@ -36,9 +33,9 @@ const GoalDetailContentSkeleton = () => (
</Flexbox>
);
-const GoalDetailSkeleton = ({ showHeader = true }: GoalDetailSkeletonProps) => (
+const GoalDetailSkeleton = ({ chrome = 'page' }: RouteSkeletonProps) => (
<Flexbox flex={1} height={'100%'}>
- {showHeader && <NavHeader />}
+ {chrome !== 'body' && <NavHeader />}
<Flexbox flex={1} style={{ overflowY: 'auto' }}>
<WideScreenContainer gap={20} paddingBlock={16}>
<GoalDetailContentSkeleton />
diff --git a/src/components/Skeleton/GroupLayout.tsx b/src/components/Skeleton/GroupLayout.tsx
deleted file mode 100644
index abed447474d..00000000000
--- a/src/components/Skeleton/GroupLayout.tsx
+++ /dev/null
@@ -1,19 +0,0 @@
-'use client';
-
-import { useLocation } from 'react-router';
-
-import ConversationLayoutSkeleton from './Conversation/Layout';
-import ProfileSkeleton from './Profile';
-import SurfaceSkeleton from './Surface';
-
-const GroupLayoutSkeleton = () => {
- const { pathname } = useLocation();
- const leaf = pathname.split('/').findLast(Boolean);
-
- if (leaf === 'profile') return <ProfileSkeleton variant={'group'} />;
- if (leaf === 'permission') return <SurfaceSkeleton variant={'form'} />;
-
- return <ConversationLayoutSkeleton />;
-};
-
-export default GroupLayoutSkeleton;
diff --git a/src/components/Skeleton/Memory.tsx b/src/components/Skeleton/Memory.tsx
index 895bd7206d7..bd7f742654d 100644
--- a/src/components/Skeleton/Memory.tsx
+++ b/src/components/Skeleton/Memory.tsx
@@ -4,12 +4,13 @@ import { Flexbox } from '@lobehub/ui';
import NavHeader from '@/features/NavHeader';
import WideScreenContainer from '@/features/WideScreenContainer';
+import type { RouteSkeletonProps } from '@/spa/router/routeMeta';
import SkeletonBar from './Bar';
-const MemorySkeleton = () => (
+const MemorySkeleton = ({ chrome = 'page' }: RouteSkeletonProps) => (
<Flexbox aria-busy flex={1} height={'100%'}>
- <NavHeader />
+ {chrome !== 'body' && <NavHeader />}
<Flexbox height={'100%'} style={{ overflow: 'hidden' }} width={'100%'}>
<WideScreenContainer gap={32} paddingBlock={48}>
<Flexbox align={'center'} gap={16} paddingBlock={'18vh 0'}>
diff --git a/src/components/Skeleton/Profile.tsx b/src/components/Skeleton/Profile.tsx
index c2150e46e8c..75f0c1fd845 100644
--- a/src/components/Skeleton/Profile.tsx
+++ b/src/components/Skeleton/Profile.tsx
@@ -4,12 +4,13 @@ import { Flexbox } from '@lobehub/ui';
import { createStaticStyles, cssVar } from 'antd-style';
import WideScreenContainer from '@/features/WideScreenContainer';
+import type { RouteSkeletonProps } from '@/spa/router/routeMeta';
import SkeletonBar from './Bar';
type ProfileSkeletonVariant = 'agent' | 'group';
-interface ProfileSkeletonProps {
+interface ProfileSkeletonProps extends RouteSkeletonProps {
variant?: ProfileSkeletonVariant;
}
@@ -102,13 +103,17 @@ const GroupProfileSkeleton = () => (
</WideScreenContainer>
);
-const ProfileSkeleton = ({ variant = 'agent' }: ProfileSkeletonProps) => (
+const ProfileSkeleton = ({ chrome = 'page', variant = 'agent' }: ProfileSkeletonProps) => (
<Flexbox aria-busy flex={1} height={'100%'} style={{ minHeight: 0, overflow: 'hidden' }}>
- <NavigationSkeleton />
+ {chrome !== 'body' && <NavigationSkeleton />}
<Flexbox flex={1} style={{ minHeight: 0, overflow: 'hidden', overflowY: 'auto' }}>
{variant === 'agent' ? <AgentProfileSkeleton /> : <GroupProfileSkeleton />}
</Flexbox>
</Flexbox>
);
+export const GroupProfileRouteSkeleton = (props: RouteSkeletonProps) => (
+ <ProfileSkeleton variant={'group'} {...props} />
+);
+
export default ProfileSkeleton;
diff --git a/src/components/Skeleton/RouteSegment.tsx b/src/components/Skeleton/RouteSegment.tsx
index 405fe1ede51..cb3dd1215aa 100644
--- a/src/components/Skeleton/RouteSegment.tsx
+++ b/src/components/Skeleton/RouteSegment.tsx
@@ -2,18 +2,17 @@
import { useLocation } from 'react-router';
+import { useRouteSkeleton } from '@/spa/router/useRouteSkeleton';
+
import AppsSkeleton from './Apps';
import ConversationLayoutSkeleton from './Conversation/Layout';
-import GoalSkeleton from './Goal';
-import GoalDetailSkeleton from './GoalDetail';
import MemorySkeleton from './Memory';
-import ProfileSkeleton from './Profile';
import SettingsPageSkeleton from './Settings/Page';
import SurfaceSkeleton, { type SurfaceSkeletonVariant } from './Surface';
const FORM_SEGMENTS = new Set(['permission', 'profile']);
const GRID_SEGMENTS = new Set(['channel', 'statistics']);
-const LIST_SEGMENTS = new Set(['history', 'memory', 'topics']);
+const LIST_SEGMENTS = new Set(['history', 'memory']);
const getSurfaceVariant = (pathname: string): SurfaceSkeletonVariant => {
const segments = pathname.split('/').filter(Boolean);
@@ -36,27 +35,16 @@ const isConversationPath = (pathname: string) => {
return segments.length === 3 && segments[2].startsWith('tpc_');
};
-/**
- * Structural fallback shared by nested route boundaries.
- *
- * It deliberately maps URLs to settled surface families instead of drawing one
- * universal placeholder. This keeps parent and leaf Suspense boundaries on the
- * same visual structure while their chunks resolve at different times.
- */
const RouteSegmentSkeleton = () => {
+ const Skeleton = useRouteSkeleton();
const { pathname } = useLocation();
const segments = pathname.split('/').filter(Boolean);
+ if (Skeleton) return <Skeleton />;
if (pathname.startsWith('/settings/')) return <SettingsPageSkeleton />;
if (segments[0] === 'apps') return <AppsSkeleton />;
if (isConversationPath(pathname)) return <ConversationLayoutSkeleton />;
if (segments[0] === 'memory' && segments.length === 1) return <MemorySkeleton />;
- if (segments[0] === 'agent' && segments[2] === 'goals') return <GoalSkeleton />;
- if (segments[0] === 'agent' && segments[2] === 'goal') return <GoalDetailSkeleton />;
- if (segments[0] === 'agent' && segments[2] === 'profile') return <ProfileSkeleton />;
- if (segments[0] === 'group' && segments[2] === 'profile') {
- return <ProfileSkeleton variant={'group'} />;
- }
return <SurfaceSkeleton variant={getSurfaceVariant(pathname)} />;
};
diff --git a/src/components/Skeleton/Tasks.tsx b/src/components/Skeleton/Tasks.tsx
new file mode 100644
index 00000000000..c2c1daa8824
--- /dev/null
+++ b/src/components/Skeleton/Tasks.tsx
@@ -0,0 +1,34 @@
+'use client';
+
+import { Block, Flexbox } from '@lobehub/ui';
+import { Divider } from 'antd';
+import { Fragment } from 'react';
+
+import TaskItemSkeleton from '@/features/AgentTasks/AgentTaskList/TaskItemSkeleton';
+import NavHeader from '@/features/NavHeader';
+import WideScreenContainer from '@/features/WideScreenContainer';
+import type { RouteSkeletonProps } from '@/spa/router/routeMeta';
+
+const TasksSkeleton = ({ chrome = 'page' }: RouteSkeletonProps) => (
+ <Flexbox aria-busy flex={1} height={'100%'}>
+ {chrome !== 'body' && <NavHeader />}
+ <WideScreenContainer
+ fullWidth
+ gap={16}
+ paddingBlock={16}
+ paddingInline={16}
+ wrapperStyle={{ flex: 1, overflowY: 'auto' }}
+ >
+ <Block gap={2} padding={2} variant={'borderless'}>
+ {Array.from({ length: 5 }).map((_, index) => (
+ <Fragment key={index}>
+ <TaskItemSkeleton />
+ {index !== 4 && <Divider dashed style={{ margin: 0 }} />}
+ </Fragment>
+ ))}
+ </Block>
+ </WideScreenContainer>
+ </Flexbox>
+);
+
+export default TasksSkeleton;
diff --git a/src/components/Skeleton/Topics.tsx b/src/components/Skeleton/Topics.tsx
new file mode 100644
index 00000000000..e85ac671e7e
--- /dev/null
+++ b/src/components/Skeleton/Topics.tsx
@@ -0,0 +1,94 @@
+'use client';
+
+import { Flexbox } from '@lobehub/ui';
+import { createStaticStyles, cssVar, responsive } from 'antd-style';
+
+import NavHeader from '@/features/NavHeader';
+import type { RouteSkeletonProps } from '@/spa/router/routeMeta';
+
+import SkeletonBar from './Bar';
+
+const styles = createStaticStyles(({ css }) => ({
+ card: css`
+ min-height: 140px;
+ padding: 14px;
+ border-radius: ${cssVar.borderRadiusLG};
+ background: ${cssVar.colorFillQuaternary};
+ `,
+ footer: css`
+ margin-block-start: auto;
+ padding-block-start: 10px;
+ border-block-start: 1px solid ${cssVar.colorSplit};
+ `,
+ grid: css`
+ display: grid;
+ grid-template-columns: repeat(auto-fill, minmax(min(280px, 100%), 1fr));
+ gap: 12px;
+
+ width: 100%;
+ min-width: 0;
+
+ ${responsive.md} {
+ grid-template-columns: repeat(auto-fill, minmax(min(240px, 100%), 1fr));
+ }
+ `,
+}));
+
+const TopicCardSkeleton = ({ index }: { index: number }) => (
+ <Flexbox className={styles.card} gap={10}>
+ <Flexbox horizontal align={'center'} gap={8}>
+ <SkeletonBar height={8} radius={'50%'} width={8} />
+ <SkeletonBar height={16} width={`${46 + (index % 3) * 10}%`} />
+ </Flexbox>
+ <SkeletonBar height={12} width={`${72 + (index % 2) * 8}%`} />
+ <SkeletonBar height={12} width={`${48 + (index % 3) * 6}%`} />
+ <Flexbox horizontal align={'center'} className={styles.footer} gap={12}>
+ <SkeletonBar height={12} width={48} />
+ <SkeletonBar height={12} width={36} />
+ <SkeletonBar height={12} width={56} />
+ </Flexbox>
+ </Flexbox>
+);
+
+const TopicGridSkeleton = () => (
+ <div aria-busy className={styles.grid}>
+ {Array.from({ length: 6 }).map((_, index) => (
+ <TopicCardSkeleton index={index} key={index} />
+ ))}
+ </div>
+);
+
+const TopicsSkeleton = ({ chrome = 'page' }: RouteSkeletonProps) => {
+ if (chrome === 'body') return <TopicGridSkeleton />;
+
+ return (
+ <Flexbox aria-busy flex={1} height={'100%'} style={{ minHeight: 0, overflow: 'hidden' }}>
+ <NavHeader />
+ <Flexbox flex={1} style={{ minHeight: 0, overflowY: 'auto', padding: '20px 24px' }}>
+ <Flexbox
+ gap={16}
+ style={{
+ marginInline: 'auto',
+ maxWidth: 1440,
+ width: '100%',
+ }}
+ >
+ <Flexbox horizontal align={'center'} gap={8} justify={'space-between'}>
+ <Flexbox horizontal gap={8}>
+ <SkeletonBar height={32} radius={16} width={72} />
+ <SkeletonBar height={32} radius={16} width={88} />
+ <SkeletonBar height={32} radius={16} width={80} />
+ </Flexbox>
+ <Flexbox horizontal gap={8}>
+ <SkeletonBar height={32} radius={8} width={36} />
+ <SkeletonBar height={32} radius={8} width={36} />
+ </Flexbox>
+ </Flexbox>
+ <TopicGridSkeleton />
+ </Flexbox>
+ </Flexbox>
+ </Flexbox>
+ );
+};
+
+export default TopicsSkeleton;
diff --git a/src/features/AgentGoals/AgentGoalsPage.tsx b/src/features/AgentGoals/AgentGoalsPage.tsx
index ef3f7b7fc5a..58b09e7e442 100644
--- a/src/features/AgentGoals/AgentGoalsPage.tsx
+++ b/src/features/AgentGoals/AgentGoalsPage.tsx
@@ -144,7 +144,7 @@ const AgentGoalsPage = memo<AgentGoalsPageProps>(({ agentId, projectId }) => {
wrapperStyle={{ flex: 1, overflowY: 'auto' }}
>
{isLoading && !isInitialized ? (
- <GoalSkeleton showHeader={false} />
+ <GoalSkeleton chrome={'body'} />
) : error ? (
<Block padding={32} variant={'outlined'}>
<Flexbox align={'center'} gap={12}>
diff --git a/src/features/AgentGoals/GoalDetailPage.tsx b/src/features/AgentGoals/GoalDetailPage.tsx
index caaefc30ff4..3d1ee5b7734 100644
--- a/src/features/AgentGoals/GoalDetailPage.tsx
+++ b/src/features/AgentGoals/GoalDetailPage.tsx
@@ -183,7 +183,7 @@ const GoalDetailPage = memo<GoalDetailPageProps>(({ agentId, goalId }) => {
<Flexbox flex={1} style={{ overflowY: 'auto' }}>
<WideScreenContainer gap={20} paddingBlock={16}>
{isInitialLoading || !task ? (
- <GoalDetailSkeleton showHeader={false} />
+ <GoalDetailSkeleton chrome={'body'} />
) : (
<>
<Flexbox className={styles.header} gap={8}>
diff --git a/src/features/AgentGoals/routeMeta.ts b/src/features/AgentGoals/routeMeta.ts
index acbe9fea227..85e3452b0c6 100644
--- a/src/features/AgentGoals/routeMeta.ts
+++ b/src/features/AgentGoals/routeMeta.ts
@@ -1,8 +1,17 @@
import { TargetIcon } from 'lucide-react';
+import GoalSkeleton from '@/components/Skeleton/Goal';
+import GoalDetailSkeleton from '@/components/Skeleton/GoalDetail';
import { routeMeta } from '@/spa/router/routeMeta';
export const goalsRouteMeta = routeMeta({
icon: TargetIcon,
+ Skeleton: GoalSkeleton,
+ titleKey: 'navigation.goals',
+});
+
+export const goalDetailRouteMeta = routeMeta({
+ icon: TargetIcon,
+ Skeleton: GoalDetailSkeleton,
titleKey: 'navigation.goals',
});
diff --git a/src/features/AgentTasks/routeMeta.ts b/src/features/AgentTasks/routeMeta.ts
index e6c1de250a8..0e2ca257cae 100644
--- a/src/features/AgentTasks/routeMeta.ts
+++ b/src/features/AgentTasks/routeMeta.ts
@@ -1,5 +1,6 @@
import { ListTodoIcon } from 'lucide-react';
+import TasksSkeleton from '@/components/Skeleton/Tasks';
import { usePublishDynamicRouteMeta } from '@/features/RouteMeta/usePublishDynamicRouteMeta';
import { matchesRouteWorkspace, useRouteWorkspaceId } from '@/features/RouteMeta/workspaceScope';
import type { DynamicRouteMetaProps } from '@/spa/router/routeMeta';
@@ -9,6 +10,7 @@ import { taskDetailSelectors } from '@/store/task/selectors';
export const tasksRouteMeta = routeMeta({
icon: ListTodoIcon,
+ Skeleton: TasksSkeleton,
titleKey: 'navigation.tasks',
});
diff --git a/src/features/AgentTopicManager/index.tsx b/src/features/AgentTopicManager/index.tsx
index 8fd92e17410..51024fc55af 100644
--- a/src/features/AgentTopicManager/index.tsx
+++ b/src/features/AgentTopicManager/index.tsx
@@ -5,12 +5,12 @@ import {
groupTopicsByProject,
groupTopicsByUpdatedTime,
} from '@lobechat/utils/client/topic';
-import { Flexbox, Skeleton } from '@lobehub/ui';
+import { Flexbox } from '@lobehub/ui';
import { memo, useEffect, useMemo, useRef } from 'react';
import { useTranslation } from 'react-i18next';
import AsyncError from '@/components/AsyncError';
-import SurfaceSkeleton from '@/components/Skeleton/Surface';
+import TopicsSkeleton from '@/components/Skeleton/Topics';
import { useChatStore } from '@/store/chat';
import { topicSelectors } from '@/store/chat/selectors';
import { shinyTextStyles } from '@/styles/loading';
@@ -200,7 +200,7 @@ const AgentTopicManager = memo(() => {
return () => observer.disconnect();
}, [hasMore, isLoadingMore, isSearchMode, loadMoreAgentTopicsView, loadMoreError]);
- if (!activeAgentId) return <SurfaceSkeleton variant={'list'} />;
+ if (!activeAgentId) return <TopicsSkeleton />;
return (
<Flexbox flex={1} height={'100%'} style={{ overflow: 'hidden' }}>
@@ -235,7 +235,7 @@ const AgentTopicManager = memo(() => {
}}
/>
) : isLoading && baseTopics.length === 0 ? (
- <Skeleton active paragraph={{ rows: 6 }} title={false} />
+ <TopicsSkeleton chrome={'body'} />
) : totalAfterFilter === 0 ? (
<EmptyState
agentId={activeAgentId}
diff --git a/src/features/Settings/features/routeMeta.ts b/src/features/Settings/features/routeMeta.ts
index f473b831064..315083eda42 100644
--- a/src/features/Settings/features/routeMeta.ts
+++ b/src/features/Settings/features/routeMeta.ts
@@ -1,6 +1,7 @@
import { Settings } from 'lucide-react';
import { useTranslation } from 'react-i18next';
+import SettingsPageSkeleton from '@/components/Skeleton/Settings/Page';
import { usePublishDynamicRouteMeta } from '@/features/RouteMeta/usePublishDynamicRouteMeta';
import type { DynamicRouteMetaProps } from '@/spa/router/routeMeta';
import { routeMeta } from '@/spa/router/routeMeta';
@@ -26,5 +27,6 @@ const SettingsDynamicMeta = ({ onResolve, params }: DynamicRouteMetaProps) => {
export const settingsRouteMeta = routeMeta({
DynamicMeta: SettingsDynamicMeta,
icon: Settings,
+ Skeleton: SettingsPageSkeleton,
titleKey: 'navigation.settings',
});
diff --git a/src/routes/(main)/agent/features/routeMeta.ts b/src/routes/(main)/agent/features/routeMeta.ts
index 53ecd73c16c..f14ab88d30d 100644
--- a/src/routes/(main)/agent/features/routeMeta.ts
+++ b/src/routes/(main)/agent/features/routeMeta.ts
@@ -9,6 +9,9 @@ import {
} from 'lucide-react';
import { lazy } from 'react';
+import ConversationLayoutSkeleton from '@/components/Skeleton/Conversation/Layout';
+import ProfileSkeleton from '@/components/Skeleton/Profile';
+import TopicsSkeleton from '@/components/Skeleton/Topics';
import { routeMeta } from '@/spa/router/routeMeta';
const AgentDynamicMeta = lazy(() => import('@/features/RouteMeta/AgentDynamicMeta'));
@@ -46,18 +49,21 @@ const PermissionDynamicMeta = lazy(() =>
export const agentRouteMeta = routeMeta({
DynamicMeta: AgentDynamicMeta,
icon: MessageSquare,
+ Skeleton: ConversationLayoutSkeleton,
titleKey: 'navigation.chat',
});
export const topicsRouteMeta = routeMeta({
DynamicMeta: TopicsDynamicMeta,
icon: MessagesSquareIcon,
+ Skeleton: TopicsSkeleton,
titleKey: 'navigation.topics',
});
export const agentProfileRouteMeta = routeMeta({
DynamicMeta: ProfileDynamicMeta,
icon: FileUserIcon,
+ Skeleton: ProfileSkeleton,
titleKey: 'navigation.profile',
});
diff --git a/src/routes/(main)/agent/topics/index.tsx b/src/routes/(main)/agent/topics/index.tsx
index 46bd4cd1b10..fc347d65ca1 100644
--- a/src/routes/(main)/agent/topics/index.tsx
+++ b/src/routes/(main)/agent/topics/index.tsx
@@ -2,11 +2,11 @@
import { Suspense } from 'react';
-import SurfaceSkeleton from '@/components/Skeleton/Surface';
+import TopicsSkeleton from '@/components/Skeleton/Topics';
import AgentTopicManager from '@/features/AgentTopicManager';
const AgentTopicsPage = () => (
- <Suspense fallback={<SurfaceSkeleton variant={'list'} />}>
+ <Suspense fallback={<TopicsSkeleton />}>
<AgentTopicManager />
</Suspense>
);
diff --git a/src/routes/(main)/group/features/routeMeta.ts b/src/routes/(main)/group/features/routeMeta.ts
index 3a836ba0f61..fa850484a25 100644
--- a/src/routes/(main)/group/features/routeMeta.ts
+++ b/src/routes/(main)/group/features/routeMeta.ts
@@ -1,6 +1,8 @@
import { FileUserIcon, Users, UsersIcon } from 'lucide-react';
import { lazy } from 'react';
+import ConversationLayoutSkeleton from '@/components/Skeleton/Conversation/Layout';
+import { GroupProfileRouteSkeleton } from '@/components/Skeleton/Profile';
import { routeMeta } from '@/spa/router/routeMeta';
const GroupDynamicMeta = lazy(() => import('@/features/RouteMeta/GroupDynamicMeta'));
@@ -18,12 +20,14 @@ const GroupPermissionDynamicMeta = lazy(() =>
export const groupRouteMeta = routeMeta({
DynamicMeta: GroupDynamicMeta,
icon: Users,
+ Skeleton: ConversationLayoutSkeleton,
titleKey: 'navigation.groupChat',
});
export const groupProfileRouteMeta = routeMeta({
DynamicMeta: GroupProfileDynamicMeta,
icon: FileUserIcon,
+ Skeleton: GroupProfileRouteSkeleton,
titleKey: 'navigation.groupProfile',
});
diff --git a/src/spa/router/desktopRouter.shared.tsx b/src/spa/router/desktopRouter.shared.tsx
index 6af932116e2..c83f3f71d53 100644
--- a/src/spa/router/desktopRouter.shared.tsx
+++ b/src/spa/router/desktopRouter.shared.tsx
@@ -28,15 +28,10 @@ import BrandTextLoading from '@/components/Loading/BrandTextLoading';
import AppsSkeleton from '@/components/Skeleton/Apps';
import ConversationLayoutSkeleton from '@/components/Skeleton/Conversation/Layout';
import ConversationSegmentSkeleton from '@/components/Skeleton/Conversation/Segment';
-import GoalSkeleton from '@/components/Skeleton/Goal';
-import GoalDetailSkeleton from '@/components/Skeleton/GoalDetail';
-import GroupLayoutSkeleton from '@/components/Skeleton/GroupLayout';
import MemorySkeleton from '@/components/Skeleton/Memory';
-import ProfileSkeleton from '@/components/Skeleton/Profile';
import RouteSegmentSkeleton from '@/components/Skeleton/RouteSegment';
-import SettingsPageSkeleton from '@/components/Skeleton/Settings/Page';
import { agentDocumentRouteMeta } from '@/features/AgentDocumentPage/routeMeta';
-import { goalsRouteMeta } from '@/features/AgentGoals/routeMeta';
+import { goalDetailRouteMeta, goalsRouteMeta } from '@/features/AgentGoals/routeMeta';
import { taskRouteMeta, tasksRouteMeta } from '@/features/AgentTasks/routeMeta';
import { agentsRouteMeta } from '@/features/AgentViewAll/routeMeta';
import { pageRouteMeta } from '@/features/Pages/routeMeta';
@@ -167,7 +162,6 @@ export const sharedMainAreaChildren: RouteObject[] = [
element: dynamicElement(
() => import('@/routes/(main)/agent/goals'),
'Desktop > Chat > Goals',
- { fallback: <GoalSkeleton /> },
),
handle: { meta: goalsRouteMeta },
path: 'goals',
@@ -176,16 +170,14 @@ export const sharedMainAreaChildren: RouteObject[] = [
element: dynamicElement(
() => import('@/routes/(main)/agent/goal/[goalId]'),
'Desktop > Chat > Goal Detail',
- { fallback: <GoalDetailSkeleton /> },
),
- handle: { meta: goalsRouteMeta },
+ handle: { meta: goalDetailRouteMeta },
path: 'goal/:goalId',
},
{
element: dynamicElement(
() => import('@/routes/(main)/agent/profile'),
'Desktop > Chat > Profile',
- { fallback: <ProfileSkeleton /> },
),
handle: { meta: agentProfileRouteMeta },
path: 'profile',
@@ -350,7 +342,6 @@ export const sharedMainAreaChildren: RouteObject[] = [
element: dynamicElement(
() => import('@/routes/(main)/group/profile'),
'Desktop > Agent Group > Profile',
- { fallback: <ProfileSkeleton variant={'group'} /> },
),
handle: { meta: groupProfileRouteMeta },
path: 'profile',
@@ -372,7 +363,7 @@ export const sharedMainAreaChildren: RouteObject[] = [
element: dynamicLayout(
() => import('@/routes/(main)/group/_layout'),
'Desktop > Group > Layout',
- { fallback: <GroupLayoutSkeleton />, preloadId: 'group' },
+ { preloadId: 'group' },
),
errorElement: <ErrorBoundary />,
path: ':gid',
@@ -692,10 +683,14 @@ export const sharedMainAreaChildren: RouteObject[] = [
element: dynamicElement(
() => import('@/routes/(main)/memory/(home)'),
'Desktop > Memory > Home',
- { fallback: <MemorySkeleton />, preloadId: 'memory' },
+ { preloadId: 'memory' },
),
handle: {
- meta: routeMeta({ icon: BrainCircuit, titleKey: 'navigation.memory' }),
+ meta: routeMeta({
+ icon: BrainCircuit,
+ Skeleton: MemorySkeleton,
+ titleKey: 'navigation.memory',
+ }),
},
index: true,
},
@@ -1028,11 +1023,11 @@ const createMainAreaChildrenDefinition = (options: MainAreaRouteOptions = {}): R
// Apps page (personal-only — never mirrored under /:workspaceSlug)
{
- element: dynamicElement(() => import('@/routes/(main)/apps'), 'Desktop > Apps', {
- fallback: <AppsSkeleton />,
- }),
+ element: dynamicElement(() => import('@/routes/(main)/apps'), 'Desktop > Apps'),
errorElement: <ErrorBoundary />,
- handle: { meta: routeMeta({ icon: Download, titleKey: 'navigation.apps' }) },
+ handle: {
+ meta: routeMeta({ icon: Download, Skeleton: AppsSkeleton, titleKey: 'navigation.apps' }),
+ },
path: 'apps',
},
@@ -1074,9 +1069,8 @@ const createMainAreaChildrenDefinition = (options: MainAreaRouteOptions = {}): R
element: dynamicElement(
() => import('@/routes/(main)/settings'),
'Desktop > Settings > Memory',
- { fallback: <SettingsPageSkeleton /> },
),
- handle: { settingsTab: SettingsTabs.Memory },
+ handle: { meta: settingsRouteMeta, settingsTab: SettingsTabs.Memory },
path: 'memory',
},
{
@@ -1088,7 +1082,6 @@ const createMainAreaChildrenDefinition = (options: MainAreaRouteOptions = {}): R
element: dynamicElement(
() => import('@/routes/(main)/settings'),
'Desktop > Settings > Tab',
- { fallback: <SettingsPageSkeleton /> },
),
handle: { meta: settingsRouteMeta },
path: ':tab',
@@ -1099,7 +1092,6 @@ const createMainAreaChildrenDefinition = (options: MainAreaRouteOptions = {}): R
element: dynamicElement(
() => import('@/routes/(main)/settings'),
'Desktop > Settings > Tab > Sub',
- { fallback: <SettingsPageSkeleton /> },
),
handle: { meta: settingsRouteMeta },
path: ':tab/:sub',
@@ -1108,9 +1100,9 @@ const createMainAreaChildrenDefinition = (options: MainAreaRouteOptions = {}): R
element: dynamicElement(
() => import('@/routes/(main)/settings/_layout'),
'Desktop > Settings > Layout',
- { fallback: <SettingsPageSkeleton /> },
),
errorElement: <ErrorBoundary />,
+ handle: { meta: settingsRouteMeta },
path: 'settings',
},
diff --git a/src/spa/router/desktopRouter.sync.test.tsx b/src/spa/router/desktopRouter.sync.test.tsx
index 03ff3f00c41..bec81457bb2 100644
--- a/src/spa/router/desktopRouter.sync.test.tsx
+++ b/src/spa/router/desktopRouter.sync.test.tsx
@@ -12,14 +12,16 @@ import ConversationLayoutSkeleton from '@/components/Skeleton/Conversation/Layou
import ConversationSegmentSkeleton from '@/components/Skeleton/Conversation/Segment';
import GoalSkeleton from '@/components/Skeleton/Goal';
import GoalDetailSkeleton from '@/components/Skeleton/GoalDetail';
-import GroupLayoutSkeleton from '@/components/Skeleton/GroupLayout';
import MemorySkeleton from '@/components/Skeleton/Memory';
-import ProfileSkeleton from '@/components/Skeleton/Profile';
+import ProfileSkeleton, { GroupProfileRouteSkeleton } from '@/components/Skeleton/Profile';
import RouteSegmentSkeleton from '@/components/Skeleton/RouteSegment';
import SettingsPageSkeleton from '@/components/Skeleton/Settings/Page';
+import TasksSkeleton from '@/components/Skeleton/Tasks';
+import TopicsSkeleton from '@/components/Skeleton/Topics';
import { WORKSPACE_SETTINGS_TABS } from '@/features/Workspace/workspaceAwarePath';
import AppShellSkeleton from '@/spa/BootShell/AppShellSkeleton';
import { createTabRouter } from '@/spa/router/tabRouter';
+import { resolveRouteSkeleton } from '@/spa/router/useRouteSkeleton';
import {
createMainAreaChildren as createWebMainAreaChildren,
@@ -330,18 +332,7 @@ describe('desktop router shared definition', () => {
expect(fallbacks.length).toBeGreaterThan(0);
expect(fallbacks).not.toContain(BrandTextLoading);
expect(new Set(fallbacks)).toEqual(
- new Set([
- AppsSkeleton,
- RouteSegmentSkeleton,
- ConversationLayoutSkeleton,
- ConversationSegmentSkeleton,
- GoalSkeleton,
- GoalDetailSkeleton,
- GroupLayoutSkeleton,
- MemorySkeleton,
- ProfileSkeleton,
- SettingsPageSkeleton,
- ]),
+ new Set([ConversationLayoutSkeleton, ConversationSegmentSkeleton, RouteSegmentSkeleton]),
);
},
);
@@ -357,7 +348,7 @@ describe('desktop router shared definition', () => {
'/agent/agent-1/topic-1',
[RouteSegmentSkeleton, ConversationLayoutSkeleton, ConversationSegmentSkeleton],
],
- ['/group/group-1/topic-1', [GroupLayoutSkeleton, ConversationLayoutSkeleton]],
+ ['/group/group-1/topic-1', [RouteSegmentSkeleton, ConversationLayoutSkeleton]],
] as const) {
const matches = matchRoutes(createRuntimeRoutes(pathname), pathname);
const fallbackTypes = matches
@@ -378,21 +369,25 @@ describe('desktop router shared definition', () => {
it.each([
['Web', (_pathname: string) => webDesktopRoutes],
['Electron', (pathname: string) => createTabRouter(pathname).routes],
- ])('%s keeps profile and goal detail route boundaries on semantic skeletons', (_, getRoutes) => {
- for (const [pathname, expectedFallbacks] of [
- ['/group/group-1/profile', [GroupLayoutSkeleton, ProfileSkeleton]],
- ['/agent/agent-1/goal/goal-1', [RouteSegmentSkeleton, GoalDetailSkeleton]],
+ ])('%s resolves specialized skeletons from the deepest route meta', (_, getRoutes) => {
+ for (const [pathname, expectedSkeleton] of [
+ ['/agent/agent-1/topics', TopicsSkeleton],
+ ['/agent/agent-1/tasks', TasksSkeleton],
+ ['/agent/agent-1/goals', GoalSkeleton],
+ ['/agent/agent-1/goal/goal-1', GoalDetailSkeleton],
+ ['/agent/agent-1/profile', ProfileSkeleton],
+ ['/agent/agent-1/topic-1', ConversationLayoutSkeleton],
+ ['/group/group-1/profile', GroupProfileRouteSkeleton],
+ ['/group/group-1/topic-1', ConversationLayoutSkeleton],
+ ['/settings/profile', SettingsPageSkeleton],
+ ['/apps', AppsSkeleton],
+ ['/memory', MemorySkeleton],
] as const) {
const matches = matchRoutes(getRoutes(pathname), pathname);
- const fallbackTypes = matches
- ?.map(
- ({ route }) =>
- (route.element as ReactElement<{ fallback?: ReactElement }> | undefined)?.props.fallback
- ?.type,
- )
- .filter(Boolean);
-
- expect(fallbackTypes?.slice(-expectedFallbacks.length), pathname).toEqual(expectedFallbacks);
+ expect(
+ resolveRouteSkeleton(matches?.map(({ route }) => ({ handle: route.handle })) ?? []),
+ pathname,
+ ).toBe(expectedSkeleton);
}
});
@@ -411,12 +406,15 @@ describe('desktop router shared definition', () => {
)
.filter(Boolean);
- expect(fallbackTypes?.slice(-2)).toEqual([SettingsPageSkeleton, SettingsPageSkeleton]);
+ expect(fallbackTypes?.slice(-2)).toEqual([RouteSegmentSkeleton, RouteSegmentSkeleton]);
},
);
- it.each(mainAreaVariants)('%s keeps /apps on the apps sheet skeleton', (_, factory) => {
- const matches = matchRoutes(createMainAreaRoutes(factory), '/apps');
+ it.each([
+ ['Web', (_pathname: string) => webDesktopRoutes],
+ ['Electron', (pathname: string) => createTabRouter(pathname).routes],
+ ])('%s keeps /apps on the route-segment fallback', (_, getRoutes) => {
+ const matches = matchRoutes(getRoutes('/apps'), '/apps');
const fallbackTypes = matches
?.map(
({ route }) =>
@@ -425,7 +423,7 @@ describe('desktop router shared definition', () => {
)
.filter(Boolean);
- expect(fallbackTypes?.at(-1)).toBe(AppsSkeleton);
+ expect(fallbackTypes?.at(-1)).toBe(RouteSegmentSkeleton);
});
it('injects Home only into Electron per-tab content routes', () => {
diff --git a/src/spa/router/routeMeta.ts b/src/spa/router/routeMeta.ts
index ce60f7bfabc..35ee6a25f23 100644
--- a/src/spa/router/routeMeta.ts
+++ b/src/spa/router/routeMeta.ts
@@ -21,8 +21,15 @@ export interface DynamicRouteMetaProps {
params: RouteMetaParams;
}
+export type RouteSkeletonChrome = 'page' | 'body';
+
+export interface RouteSkeletonProps {
+ chrome?: RouteSkeletonChrome;
+}
+
export interface RouteMeta extends StaticRouteMeta {
DynamicMeta?: ComponentType<DynamicRouteMetaProps>;
+ Skeleton?: ComponentType<RouteSkeletonProps>;
}
export interface RouteHandle {
diff --git a/src/spa/router/useRouteSkeleton.test.ts b/src/spa/router/useRouteSkeleton.test.ts
new file mode 100644
index 00000000000..f1ce393926f
--- /dev/null
+++ b/src/spa/router/useRouteSkeleton.test.ts
@@ -0,0 +1,32 @@
+import { describe, expect, it } from 'vitest';
+
+import TopicsSkeleton from '@/components/Skeleton/Topics';
+import { routeMeta } from '@/spa/router/routeMeta';
+
+import { resolveRouteSkeleton } from './useRouteSkeleton';
+
+describe('resolveRouteSkeleton', () => {
+ it('returns the deepest match that declares a skeleton', () => {
+ const Skeleton = resolveRouteSkeleton([
+ { handle: { meta: routeMeta({ titleKey: 'navigation.chat' }) } },
+ { handle: { meta: routeMeta({ Skeleton: TopicsSkeleton, titleKey: 'navigation.topics' }) } },
+ ]);
+
+ expect(Skeleton).toBe(TopicsSkeleton);
+ });
+
+ it('skips matches without a skeleton and uses the nearest ancestor', () => {
+ const Skeleton = resolveRouteSkeleton([
+ { handle: { meta: routeMeta({ Skeleton: TopicsSkeleton, titleKey: 'navigation.topics' }) } },
+ { handle: { meta: routeMeta({ titleKey: 'navigation.permission' }) } },
+ ]);
+
+ expect(Skeleton).toBe(TopicsSkeleton);
+ });
+
+ it('returns undefined when no match declares a skeleton', () => {
+ expect(
+ resolveRouteSkeleton([{ handle: { meta: routeMeta({ titleKey: 'navigation.chat' }) } }]),
+ ).toBeUndefined();
+ });
+});
diff --git a/src/spa/router/useRouteSkeleton.ts b/src/spa/router/useRouteSkeleton.ts
new file mode 100644
index 00000000000..eb17c670335
--- /dev/null
+++ b/src/spa/router/useRouteSkeleton.ts
@@ -0,0 +1,22 @@
+import type { ComponentType } from 'react';
+import { useMemo } from 'react';
+import { useMatches } from 'react-router';
+
+import { getRouteMetaFromHandle, type RouteSkeletonProps } from './routeMeta';
+
+export const resolveRouteSkeleton = (
+ matches: Array<{ handle?: unknown }>,
+): ComponentType<RouteSkeletonProps> | undefined => {
+ for (let i = matches.length - 1; i >= 0; i -= 1) {
+ const Skeleton = getRouteMetaFromHandle(matches[i].handle)?.Skeleton;
+ if (Skeleton) return Skeleton;
+ }
+
+ return undefined;
+};
+
+export const useRouteSkeleton = () => {
+ const matches = useMatches();
+
+ return useMemo(() => resolveRouteSkeleton(matches), [matches]);
+};