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.

🐛 fix(desktop): show each page's own title in Recent Pages (#23223)

Lobehub Coderc3741d6f8dd1
diff --git a/src/features/Channels/ChannelDynamicMeta.test.ts b/src/features/Channels/ChannelDynamicMeta.test.ts
index 9fafbcbdf0b..39096c919fd 100644
--- a/src/features/Channels/ChannelDynamicMeta.test.ts
+++ b/src/features/Channels/ChannelDynamicMeta.test.ts
@@ -6,7 +6,7 @@ import { useAgentStore } from '@/store/agent';
import { useChannelStore } from '@/store/channel';
import { channelViewKey } from '@/store/channel/projection';
-import ChannelDynamicMeta from './ChannelDynamicMeta';
+import ChannelDynamicMeta, { ChannelSettingsDynamicMeta } from './ChannelDynamicMeta';
vi.mock('@/features/RouteMeta/workspaceScope', () => ({
matchesRouteWorkspace: () => true,
@@ -95,3 +95,21 @@ describe('ChannelDynamicMeta', () => {
);
});
});
+
+describe('ChannelSettingsDynamicMeta', () => {
+ beforeEach(() => {
+ useAgentStore.setState({ agentMap: {} });
+ useChannelStore.setState({ detailMap: {}, listMap: {} });
+ });
+
+ it('names the channel it configures next to the settings label', () => {
+ useChannelStore.setState({ listMap: { all: [listItem({})] } });
+ const onResolve = vi.fn();
+
+ renderHook(() =>
+ ChannelSettingsDynamicMeta({ onResolve, params: { channelId: 'chn_000000000001' } }),
+ );
+
+ expect(onResolve).toHaveBeenLastCalledWith({ title: 'settings.title · Design' });
+ });
+});
diff --git a/src/features/Channels/ChannelDynamicMeta.tsx b/src/features/Channels/ChannelDynamicMeta.tsx
index 4a8bf3b62f0..fb272cb9b7f 100644
--- a/src/features/Channels/ChannelDynamicMeta.tsx
+++ b/src/features/Channels/ChannelDynamicMeta.tsx
@@ -1,6 +1,8 @@
+import { useTranslation } from 'react-i18next';
+
import { usePublishDynamicRouteMeta } from '@/features/RouteMeta/usePublishDynamicRouteMeta';
import { matchesRouteWorkspace, useRouteWorkspaceId } from '@/features/RouteMeta/workspaceScope';
-import type { DynamicRouteMetaProps } from '@/spa/router/routeMeta';
+import type { DynamicRouteMetaProps, RouteMetaParams } from '@/spa/router/routeMeta';
import { useAgentStore } from '@/store/agent';
import { channelSelectors, useChannelStore } from '@/store/channel';
@@ -8,7 +10,7 @@ import { channelSelectors, useChannelStore } from '@/store/channel';
* Names the tab after the open Channel, from data the sidebar and page already loaded. A direct
* conversation stands for its Agent, so its tab wears that Agent's avatar instead of `#`.
*/
-const ChannelDynamicMeta = ({ onResolve, params }: DynamicRouteMetaProps) => {
+const useRouteChannel = (params: RouteMetaParams) => {
const routeWorkspaceId = useRouteWorkspaceId(params);
const channelId = params.channelId ?? '';
const detail = useChannelStore(channelSelectors.detail({ channelId, threadId: null }));
@@ -17,7 +19,13 @@ const ChannelDynamicMeta = ({ onResolve, params }: DynamicRouteMetaProps) => {
channelSelectors.list(state)?.find((item) => item.id === channelId) ?? detail?.channel,
);
const visible = !!channel && matchesRouteWorkspace(channel.workspaceId, routeWorkspaceId);
- const agentId = visible ? (channel.agentId ?? undefined) : undefined;
+
+ return { channel: visible ? channel : undefined, detail };
+};
+
+const ChannelDynamicMeta = ({ onResolve, params }: DynamicRouteMetaProps) => {
+ const { channel, detail } = useRouteChannel(params);
+ const agentId = channel?.agentId ?? undefined;
const agent = useAgentStore((state) => (agentId ? state.agentMap[agentId] : undefined));
// The page loads members before the Agent itself, so the member row covers the first paint.
const memberAvatar = agentId
@@ -34,7 +42,19 @@ const ChannelDynamicMeta = ({ onResolve, params }: DynamicRouteMetaProps) => {
backgroundColor: agent?.backgroundColor || undefined,
title: channel?.title,
}
- : { title: visible ? channel.title : undefined },
+ : { title: channel?.title },
+ onResolve,
+ );
+ return null;
+};
+
+/** The settings page keeps its own label and names the Channel it configures. */
+export const ChannelSettingsDynamicMeta = ({ onResolve, params }: DynamicRouteMetaProps) => {
+ const { t } = useTranslation('channel');
+ const { channel } = useRouteChannel(params);
+
+ usePublishDynamicRouteMeta(
+ { title: channel?.title ? `${t('settings.title')} · ${channel.title}` : undefined },
onResolve,
);
return null;
diff --git a/src/features/Channels/routeMeta.ts b/src/features/Channels/routeMeta.ts
index 82906dca9a7..c710ca6be08 100644
--- a/src/features/Channels/routeMeta.ts
+++ b/src/features/Channels/routeMeta.ts
@@ -7,6 +7,11 @@ import { routeMeta } from '@/spa/router/routeMeta';
// Route metas load with the router on first paint; keep the Channel store out of that graph.
const ChannelDynamicMeta = lazy(() => import('./ChannelDynamicMeta'));
+const ChannelSettingsDynamicMeta = lazy(() =>
+ import('./ChannelDynamicMeta').then((module) => ({
+ default: module.ChannelSettingsDynamicMeta,
+ })),
+);
export const channelRouteMeta = routeMeta({
DynamicMeta: ChannelDynamicMeta,
@@ -16,6 +21,7 @@ export const channelRouteMeta = routeMeta({
});
export const channelSettingsRouteMeta = routeMeta({
+ DynamicMeta: ChannelSettingsDynamicMeta,
icon: Settings,
Skeleton: createSurfaceSkeleton('form'),
titleKey: 'channel:settings.title',
diff --git a/src/features/Projects/routeMeta.ts b/src/features/Projects/routeMeta.ts
index e51025e8b46..af55b2c5d5e 100644
--- a/src/features/Projects/routeMeta.ts
+++ b/src/features/Projects/routeMeta.ts
@@ -3,6 +3,9 @@ import { lazy } from 'react';
import ConversationSegmentSkeleton from '@/components/Skeleton/Conversation/Segment';
import { createSurfaceSkeleton } from '@/components/Skeleton/Surface';
+import { goalsRouteMeta } from '@/features/AgentGoals/routeMeta';
+import { tasksRouteMeta } from '@/features/AgentTasks/routeMeta';
+import { dashboardsRouteMeta } from '@/features/Dashboard/routeMeta';
import { routeMeta } from '@/spa/router/routeMeta';
// Route metas load with the router on first paint; the runner reads the chat
@@ -52,3 +55,20 @@ export const projectAcceptanceRouteMeta = routeMeta({
Skeleton: createSurfaceSkeleton('detail'),
titleKey: 'project:sections.acceptance',
});
+
+// Shared list metas mounted inside a project take on the project's avatar like its other
+// sections, so two projects' Goals / Tasks / Dashboards are told apart in tabs and history.
+export const projectGoalsRouteMeta = routeMeta({
+ ...goalsRouteMeta,
+ DynamicMeta: ProjectSectionDynamicMeta,
+});
+
+export const projectTasksRouteMeta = routeMeta({
+ ...tasksRouteMeta,
+ DynamicMeta: ProjectSectionDynamicMeta,
+});
+
+export const projectDashboardsRouteMeta = routeMeta({
+ ...dashboardsRouteMeta,
+ DynamicMeta: ProjectSectionDynamicMeta,
+});
diff --git a/src/features/RouteMeta/AgentDynamicMeta.tsx b/src/features/RouteMeta/AgentDynamicMeta.tsx
index f4e7ad1026c..38a1e0dd28f 100644
--- a/src/features/RouteMeta/AgentDynamicMeta.tsx
+++ b/src/features/RouteMeta/AgentDynamicMeta.tsx
@@ -110,5 +110,11 @@ export const StatisticsDynamicMeta = createAgentSectionDynamicMeta('navigation.s
export const ShareDynamicMeta = createAgentSectionDynamicMeta('navigation.agentShare');
export const SelfLearningDynamicMeta = createAgentSectionDynamicMeta('navigation.selfLearning');
export const PermissionDynamicMeta = createAgentSectionDynamicMeta('navigation.permission');
+export const DocumentsDynamicMeta = createAgentSectionDynamicMeta('navigation.document');
+export const GoalsDynamicMeta = createAgentSectionDynamicMeta('navigation.goals');
+export const TasksDynamicMeta = createAgentSectionDynamicMeta('navigation.tasks');
+export const MailDynamicMeta = createAgentSectionDynamicMeta('navigation.mail');
+export const AutomationsDynamicMeta = createAgentSectionDynamicMeta('navigation.automations');
+export const WebhookDynamicMeta = createAgentSectionDynamicMeta('navigation.webhook');
export default AgentDynamicMeta;
diff --git a/src/routes/(main)/agent/features/routeMeta.ts b/src/routes/(main)/agent/features/routeMeta.ts
index 6fe3f71a741..b2a5c75fb6f 100644
--- a/src/routes/(main)/agent/features/routeMeta.ts
+++ b/src/routes/(main)/agent/features/routeMeta.ts
@@ -1,6 +1,7 @@
import {
ChartColumnBigIcon,
CpuIcon,
+ FileTextIcon,
FileUserIcon,
GraduationCapIcon,
LibraryBigIcon,
@@ -30,7 +31,9 @@ import ConversationLayoutSkeleton from '@/components/Skeleton/Conversation/Layou
import ProfileSkeleton from '@/components/Skeleton/Profile';
import { createSurfaceSkeleton } from '@/components/Skeleton/Surface';
import TopicsSkeleton from '@/components/Skeleton/Topics';
-import { routeMeta } from '@/spa/router/routeMeta';
+import { goalsRouteMeta } from '@/features/AgentGoals/routeMeta';
+import { tasksRouteMeta } from '@/features/AgentTasks/routeMeta';
+import { NoRouteSkeleton, routeMeta } from '@/spa/router/routeMeta';
const AgentDynamicMeta = lazy(() => import('@/features/RouteMeta/AgentDynamicMeta'));
const TopicsDynamicMeta = lazy(() =>
@@ -99,6 +102,37 @@ const PermissionDynamicMeta = lazy(() =>
})),
);
+const DocumentsDynamicMeta = lazy(() =>
+ import('@/features/RouteMeta/AgentDynamicMeta').then((module) => ({
+ default: module.DocumentsDynamicMeta,
+ })),
+);
+const GoalsDynamicMeta = lazy(() =>
+ import('@/features/RouteMeta/AgentDynamicMeta').then((module) => ({
+ default: module.GoalsDynamicMeta,
+ })),
+);
+const TasksDynamicMeta = lazy(() =>
+ import('@/features/RouteMeta/AgentDynamicMeta').then((module) => ({
+ default: module.TasksDynamicMeta,
+ })),
+);
+const MailDynamicMeta = lazy(() =>
+ import('@/features/RouteMeta/AgentDynamicMeta').then((module) => ({
+ default: module.MailDynamicMeta,
+ })),
+);
+const AutomationsDynamicMeta = lazy(() =>
+ import('@/features/RouteMeta/AgentDynamicMeta').then((module) => ({
+ default: module.AutomationsDynamicMeta,
+ })),
+);
+const WebhookDynamicMeta = lazy(() =>
+ import('@/features/RouteMeta/AgentDynamicMeta').then((module) => ({
+ default: module.WebhookDynamicMeta,
+ })),
+);
+
export const agentRouteMeta = routeMeta({
DynamicMeta: AgentDynamicMeta,
icon: MessageSquare,
@@ -169,18 +203,21 @@ export const agentToolsRouteMeta = routeMeta({
});
export const agentMailRouteMeta = routeMeta({
+ DynamicMeta: MailDynamicMeta,
icon: MailIcon,
Skeleton: createSurfaceSkeleton('list'),
titleKey: 'navigation.mail',
});
export const agentAutomationsRouteMeta = routeMeta({
+ DynamicMeta: AutomationsDynamicMeta,
icon: ZapIcon,
Skeleton: createSurfaceSkeleton('list'),
titleKey: 'navigation.automations',
});
export const agentWebhookRouteMeta = routeMeta({
+ DynamicMeta: WebhookDynamicMeta,
icon: WebhookIcon,
Skeleton: createSurfaceSkeleton('list'),
titleKey: 'navigation.webhook',
@@ -226,3 +263,22 @@ export const agentPermissionRouteMeta = routeMeta({
Skeleton: createSurfaceSkeleton('form'),
titleKey: 'navigation.permission',
});
+
+// Goals and Tasks are also mounted at workspace and project level, where there is no
+// agent to name, so only their agent-scoped mounts take the agent section title.
+export const agentGoalsRouteMeta = routeMeta({
+ ...goalsRouteMeta,
+ DynamicMeta: GoalsDynamicMeta,
+});
+
+export const agentTasksRouteMeta = routeMeta({
+ ...tasksRouteMeta,
+ DynamicMeta: TasksDynamicMeta,
+});
+
+export const agentDocumentsRouteMeta = routeMeta({
+ DynamicMeta: DocumentsDynamicMeta,
+ icon: FileTextIcon,
+ Skeleton: NoRouteSkeleton,
+ titleKey: 'navigation.document',
+});
diff --git a/src/spa/router/agentPageRoutes.tsx b/src/spa/router/agentPageRoutes.tsx
index e69c63fdec4..489f4666215 100644
--- a/src/spa/router/agentPageRoutes.tsx
+++ b/src/spa/router/agentPageRoutes.tsx
@@ -1,15 +1,16 @@
-import { FileTextIcon } from 'lucide-react';
import type { RouteObject } from 'react-router';
import { agentDocumentRouteMeta } from '@/features/AgentDocumentPage/routeMeta';
-import { goalDetailRouteMeta, goalsRouteMeta } from '@/features/AgentGoals/routeMeta';
-import { taskRouteMeta, tasksRouteMeta } from '@/features/AgentTasks/routeMeta';
+import { goalDetailRouteMeta } from '@/features/AgentGoals/routeMeta';
+import { taskRouteMeta } from '@/features/AgentTasks/routeMeta';
import {
agentAutomationsRouteMeta,
agentChannelDetailRouteMeta,
agentChannelRouteMeta,
+ agentDocumentsRouteMeta,
agentEngineRouteMeta,
agentEnvironmentRouteMeta,
+ agentGoalsRouteMeta,
agentInstructionRouteMeta,
agentKnowledgeRouteMeta,
agentMailRouteMeta,
@@ -19,6 +20,7 @@ import {
agentShareRouteMeta,
agentSkillsRouteMeta,
agentStatisticsRouteMeta,
+ agentTasksRouteMeta,
agentToolsRouteMeta,
agentWebhookRouteMeta,
topicsRouteMeta,
@@ -45,13 +47,7 @@ export const agentPageChildren: RouteObject[] = [
() => import('@/routes/(main)/agent/docs'),
'Desktop > Chat > DocumentsIndex',
),
- handle: {
- meta: routeMeta({
- icon: FileTextIcon,
- Skeleton: NoRouteSkeleton,
- titleKey: 'navigation.document',
- }),
- },
+ handle: { meta: agentDocumentsRouteMeta },
index: true,
},
{
@@ -73,7 +69,7 @@ export const agentPageChildren: RouteObject[] = [
},
{
element: dynamicElement(() => import('@/routes/(main)/agent/goals'), 'Desktop > Chat > Goals'),
- handle: { meta: goalsRouteMeta },
+ handle: { meta: agentGoalsRouteMeta },
path: 'goals',
},
{
@@ -284,7 +280,7 @@ export const agentPageChildren: RouteObject[] = [
},
{
element: dynamicElement(() => import('@/routes/(main)/agent/tasks'), 'Desktop > Chat > Tasks'),
- handle: { meta: tasksRouteMeta },
+ handle: { meta: agentTasksRouteMeta },
loader: scheduledTaskListLoader,
path: 'tasks',
},
diff --git a/src/spa/router/desktopRouter.dynamicMeta.desktop.test.ts b/src/spa/router/desktopRouter.dynamicMeta.desktop.test.ts
new file mode 100644
index 00000000000..ef5a5ded32d
--- /dev/null
+++ b/src/spa/router/desktopRouter.dynamicMeta.desktop.test.ts
@@ -0,0 +1,66 @@
+import type { RouteObject } from 'react-router';
+import { describe, expect, it } from 'vitest';
+
+import { mainAreaMetaRoutes } from './desktopRouter.config.desktop';
+import { getRouteMetaFromHandle, type RouteMeta } from './routeMeta';
+
+// Params that pick a fixed section or view, not a record with a name of its own.
+const VIEW_PARAMS = new Set([
+ ':category',
+ ':platform',
+ ':section',
+ ':sub',
+ ':tab',
+ ':workspaceSlug',
+]);
+
+// Leaves that never paint a page of their own: they redirect to the canonical URL.
+const REDIRECT_PATHS = new Set([
+ '/agent/:aid/self-evolving/:domainId/rules',
+ '/agent/:aid/self-evolving/:domainId/rules/:lessonId',
+ '/agent/:aid/self-learning/*',
+ '/agent/:aid/stats',
+ '/project/:projectId/conversation/:topicId?',
+ '/settings/provider/:providerId',
+]);
+
+// Known gap: the eval workspace has no tab titles at all yet, static or dynamic.
+const isEval = (path: string) => path.startsWith('/eval/');
+
+interface Leaf {
+ meta?: RouteMeta;
+ path: string;
+}
+
+const collectLeaves = (routes: RouteObject[], prefix = '', inherited?: RouteMeta): Leaf[] =>
+ routes.flatMap((route) => {
+ const path = route.index ? prefix : `${prefix}/${route.path ?? ''}`.replaceAll(/\/+/g, '/');
+ const meta = getRouteMetaFromHandle(route.handle) ?? inherited;
+ if (route.children?.length) return collectLeaves(route.children, path, meta);
+ return [{ meta, path }];
+ });
+
+// A page that names a record ("this goal", "this agent's tasks") but registers no
+// DynamicMeta is titled by its static label alone, so its tabs, Recent Pages and pinned
+// pages all read "Goals", "Goals", "Goals".
+describe('desktop route DynamicMeta registration', () => {
+ const leaves = collectLeaves(mainAreaMetaRoutes)
+ // Workspace-scoped mounts repeat the personal tree under `/:workspaceSlug`.
+ .map((leaf) => ({ ...leaf, path: leaf.path.replace(/^\/:workspaceSlug(?=\/)/, '') }))
+ .filter(({ path }) => !REDIRECT_PATHS.has(path) && !isEval(path))
+ .filter(({ path }) =>
+ (path.match(/:\w+\??/g) ?? []).some((param) => !VIEW_PARAMS.has(param.replace('?', ''))),
+ );
+
+ it('collects record pages from the desktop meta tree', () => {
+ expect(leaves.length).toBeGreaterThan(50);
+ });
+
+ it('gives every record page a DynamicMeta', () => {
+ const missing = [
+ ...new Set(leaves.filter(({ meta }) => !meta?.DynamicMeta).map((l) => l.path)),
+ ];
+
+ expect(missing).toEqual([]);
+ });
+});
diff --git a/src/spa/router/projectWorkspaceRoutes.tsx b/src/spa/router/projectWorkspaceRoutes.tsx
index 73ed8998cc1..67c0b4203eb 100644
--- a/src/spa/router/projectWorkspaceRoutes.tsx
+++ b/src/spa/router/projectWorkspaceRoutes.tsx
@@ -1,13 +1,14 @@
import { Navigate, type RouteObject, useLocation, useParams } from 'react-router';
-import { goalsRouteMeta } from '@/features/AgentGoals/routeMeta';
-import { tasksRouteMeta } from '@/features/AgentTasks/routeMeta';
import { channelRouteMeta, channelSettingsRouteMeta } from '@/features/Channels/routeMeta';
-import { dashboardRouteMeta, dashboardsRouteMeta } from '@/features/Dashboard/routeMeta';
+import { dashboardRouteMeta } from '@/features/Dashboard/routeMeta';
import {
projectConversationRouteMeta,
+ projectDashboardsRouteMeta,
projectDirectoriesRouteMeta,
+ projectGoalsRouteMeta,
projectHomeRouteMeta,
+ projectTasksRouteMeta,
} from '@/features/Projects/routeMeta';
import { projectAcceptanceRoute } from '@/spa/router/projectAcceptanceRoutes';
import { scheduledTaskListLoader } from '@/spa/router/scheduledTaskListLoader';
@@ -74,7 +75,7 @@ export const projectWorkspaceRoute: RouteObject = {
() => import('@/routes/(main)/project/[projectId]/tasks'),
'Desktop > Project Tasks',
),
- handle: { meta: tasksRouteMeta },
+ handle: { meta: projectTasksRouteMeta },
loader: scheduledTaskListLoader,
path: 'tasks',
},
@@ -92,7 +93,7 @@ export const projectWorkspaceRoute: RouteObject = {
() => import('@/routes/(main)/project/[projectId]/goals'),
'Desktop > Project Goals',
),
- handle: { meta: goalsRouteMeta },
+ handle: { meta: projectGoalsRouteMeta },
path: 'goals',
},
{
@@ -103,7 +104,7 @@ export const projectWorkspaceRoute: RouteObject = {
'Desktop > Project Dashboards',
{ preloadId: 'dashboard' },
),
- handle: { meta: dashboardsRouteMeta },
+ handle: { meta: projectDashboardsRouteMeta },
index: true,
},
{
diff --git a/src/store/electron/actions/__tests__/recentPages.test.ts b/src/store/electron/actions/__tests__/recentPages.test.ts
index 980dfe65c8d..23bb1bca0ce 100644
--- a/src/store/electron/actions/__tests__/recentPages.test.ts
+++ b/src/store/electron/actions/__tests__/recentPages.test.ts
@@ -1,7 +1,10 @@
import { act, renderHook } from '@testing-library/react';
import { beforeEach, describe, expect, it, vi } from 'vitest';
-import { PINNED_PAGES_STORAGE_KEY_V3 } from '@/features/Electron/titlebar/RecentlyViewed/storage';
+import {
+ PINNED_PAGES_STORAGE_KEY_V3,
+ pinnedPagesStorageKey,
+} from '@/features/Electron/titlebar/RecentlyViewed/storage';
import { type TabItem } from '@/features/Electron/titlebar/TabBar/types';
import { useElectronStore } from '@/store/electron';
import { initialState } from '@/store/electron/initialState';
@@ -64,6 +67,59 @@ describe('recentPages actions', () => {
});
});
+ // Regression: recent entries were recorded from the url alone, so every goal / topic /
+ // document fell back to its static route label ("Goals", "Goals", "Goals").
+ describe('resolved titles', () => {
+ const goalUrl = '/agent/agt_1/goal/goal_1';
+
+ it('seeds a new recent entry from the open tab that already resolved its title', () => {
+ useElectronStore.setState({
+ tabs: [{ ...buildTab(goalUrl, { title: 'Ship the launch post' }), id: 'tab_1' }],
+ });
+ const { result } = renderHook(() => useElectronStore());
+
+ act(() => {
+ result.current.addRecentPage(goalUrl);
+ });
+
+ expect(result.current.recentPages[0].cached?.title).toBe('Ship the launch post');
+ });
+
+ it('carries a title resolved after the visit into the recent entry without reordering', () => {
+ useElectronStore.setState({ tabs: [{ ...buildTab(goalUrl), id: 'tab_1' }] });
+ const { result } = renderHook(() => useElectronStore());
+
+ act(() => {
+ result.current.addRecentPage(goalUrl);
+ result.current.addRecentPage('/agent/agt_1/goals');
+ });
+ const before = result.current.recentPages.map((page) => [page.id, page.lastVisited]);
+
+ act(() => {
+ result.current.updateTabCache('tab_1', { title: 'Ship the launch post' });
+ });
+
+ const entry = result.current.recentPages.find((page) => page.id === goalUrl);
+ expect(entry?.cached?.title).toBe('Ship the launch post');
+ expect(result.current.recentPages.map((page) => [page.id, page.lastVisited])).toEqual(before);
+ });
+
+ it('carries a resolved title into a pinned entry and persists it', () => {
+ useElectronStore.setState({ tabs: [{ ...buildTab(goalUrl), id: 'tab_1' }] });
+ const { result } = renderHook(() => useElectronStore());
+
+ act(() => {
+ result.current.pinPage(buildTab(goalUrl));
+ result.current.updateTabCache('tab_1', { title: 'Ship the launch post' });
+ });
+
+ expect(result.current.pinnedPages[0].cached?.title).toBe('Ship the launch post');
+ expect(window.localStorage.getItem(pinnedPagesStorageKey({ type: 'personal' }))).toContain(
+ 'Ship the launch post',
+ );
+ });
+ });
+
describe('pinPage', () => {
it('pins personal and workspace URLs into independent buckets', () => {
const { result } = renderHook(() => useElectronStore());
diff --git a/src/store/electron/actions/recentPages.ts b/src/store/electron/actions/recentPages.ts
index 10b163f1b61..b2b59b70526 100644
--- a/src/store/electron/actions/recentPages.ts
+++ b/src/store/electron/actions/recentPages.ts
@@ -65,7 +65,10 @@ export class RecentPagesActionImpl {
const pinnedIndex = pinnedPages.findIndex((p) => isSameTabTarget(p, url));
if (pinnedIndex >= 0) {
- const merged = guardedMergeCache(pinnedPages[pinnedIndex].cached, cached);
+ const merged = guardedMergeCache(
+ pinnedPages[pinnedIndex].cached,
+ cached ?? this.#openTabCache(url),
+ );
if (merged === pinnedPages[pinnedIndex].cached) return;
const updatedPinned = [...pinnedPages];
@@ -79,7 +82,7 @@ export class RecentPagesActionImpl {
const existingEntry = existingIndex >= 0 ? recentPages[existingIndex] : null;
const newEntry: TabItem = {
- cached: guardedMergeCache(existingEntry?.cached, cached),
+ cached: guardedMergeCache(existingEntry?.cached, cached ?? this.#openTabCache(url)),
id,
lastVisited: Date.now(),
url,
@@ -139,6 +142,39 @@ export class RecentPagesActionImpl {
this.#savePinned(newPinned);
};
+ /**
+ * A page's title and avatar resolve after the visit is recorded. Tabs learn them through
+ * `updateTabCache`, which forwards them here so the matching recent or pinned entry is not
+ * left on its static route label. Only the cache changes, never the visit order.
+ */
+ updateRecentPageCache = (url: string, cached: DynamicRouteMeta): void => {
+ if (tabScopeKey(resolveTabScope(url)) !== tabScopeKey(this.#get().activeRecentScope)) return;
+
+ const { pinnedPages, recentPages } = this.#get();
+
+ const pinnedIndex = pinnedPages.findIndex((p) => isSameTabTarget(p, url));
+ if (pinnedIndex >= 0) {
+ const merged = guardedMergeCache(pinnedPages[pinnedIndex].cached, cached);
+ if (merged === pinnedPages[pinnedIndex].cached) return;
+
+ const updatedPinned = [...pinnedPages];
+ updatedPinned[pinnedIndex] = { ...updatedPinned[pinnedIndex], cached: merged };
+ this.#set(this.#withActivePinned(updatedPinned), false, 'updateRecentPageCache');
+ this.#savePinned(updatedPinned);
+ return;
+ }
+
+ const recentIndex = recentPages.findIndex((p) => isSameTabTarget(p, url));
+ if (recentIndex < 0) return;
+
+ const merged = guardedMergeCache(recentPages[recentIndex].cached, cached);
+ if (merged === recentPages[recentIndex].cached) return;
+
+ const updatedRecent = [...recentPages];
+ updatedRecent[recentIndex] = { ...updatedRecent[recentIndex], cached: merged };
+ this.#set(this.#withActiveRecent(updatedRecent), false, 'updateRecentPageCache');
+ };
+
removeRecentPage = (id: string): void => {
const { recentPages } = this.#get();
this.#set(
@@ -168,6 +204,11 @@ export class RecentPagesActionImpl {
this.#savePinned(newPinned);
};
+ // The visit is recorded when the location changes, often after the tab already resolved
+ // its title, so a new entry starts from what the open tab knows.
+ #openTabCache = (url: string): DynamicRouteMeta | undefined =>
+ this.#get().tabs.find((tab) => isSameTabTarget(tab, url))?.cached;
+
#ensureScopeForUrl = (url: string): void => {
this.#loadScope(resolveTabScope(url));
};
diff --git a/src/store/electron/actions/tabPages.ts b/src/store/electron/actions/tabPages.ts
index 7f8c25cd098..90c8da86ae3 100644
--- a/src/store/electron/actions/tabPages.ts
+++ b/src/store/electron/actions/tabPages.ts
@@ -501,6 +501,7 @@ export class TabPagesActionImpl {
this.#set({ tabs: newTabs }, false, 'updateTabCache');
this.#persist();
+ this.#get().updateRecentPageCache(tabs[index].url, cached);
};
// Pinning is a retention promise, so a bulk close only ever narrows the unpinned run —