Skip to content

armgit / cindy

Public Imported from GitHub
0

Consider it done. The open-source AI agent that works out of the box · 想到,就能做到。开源、开箱即用的 AI Agent。

fix(desktop): 修复远程任务侧边栏加载闪烁 (#1713)

Liziacd3beeb761c
diff --git a/apps/desktop/src/renderer/__tests__/dialogueSidebarSection.test.ts b/apps/desktop/src/renderer/__tests__/dialogueSidebarSection.test.ts
index 9ee7030021..8d5fa225f8 100644
--- a/apps/desktop/src/renderer/__tests__/dialogueSidebarSection.test.ts
+++ b/apps/desktop/src/renderer/__tests__/dialogueSidebarSection.test.ts
@@ -106,6 +106,20 @@ describe('Dialogue sidebar section', () => {
);
});
+ it('keeps remote background loading from changing the sidebar layout', () => {
+ // Existing local/cached rows must stay in place while remote bootstrap runs in the background.
+ // A partial loading notice in the scroll flow makes every row jump when it mounts/unmounts.
+ expect(sidebarSource).toContain(
+ '远程任务 / 设备目录的 loading 只在上面的「无内容」分支显示',
+ );
+ expect(sidebarSource).not.toMatch(
+ /remoteDeviceDirectoryStatus === 'loading'\s*&&\s*\n?\s*\(\s*<RemoteSidebarLoadNotice[\s\S]*?partial\s*\/\>\s*\)/,
+ );
+ expect(sidebarSource).not.toMatch(
+ /remoteSessionBootstrapLoadingDevices\.length > 0\s*&&\s*\n?\s*\(\s*<RemoteSidebarLoadNotice[\s\S]*?partial\s*\n?\s*\/\>\s*\)/,
+ );
+ });
+
it('has a Dialogue-owned runtime sort setting instead of using project manual order or renderer storage', () => {
expect(dialogueSectionSource).toContain('DIALOGUE_SORT_OPTIONS');
expect(dialogueSectionSource).not.toMatch(/manualProjectOrder/);
diff --git a/apps/desktop/src/renderer/__tests__/machineSwitcherMenu.test.ts b/apps/desktop/src/renderer/__tests__/machineSwitcherMenu.test.ts
index 1614c19e12..1d9f4915d4 100644
--- a/apps/desktop/src/renderer/__tests__/machineSwitcherMenu.test.ts
+++ b/apps/desktop/src/renderer/__tests__/machineSwitcherMenu.test.ts
@@ -196,6 +196,20 @@ describe('远程机器切换入口并入 SidebarTopNav(置顶段上方,固定不
}
});
+ it('在机器栏固定显示远程任务读取 loading,不改变文字与下拉箭头间距', () => {
+ // 文字与箭头保持原有相邻布局;后台 bootstrap 只占最右侧固定状态槽,
+ // 避免列表上下跳动,也避免空槽把下拉箭头推远。
+ expect(menuSource).toContain('useRemoteSessionBootstrapLoading(selectedDeviceId)');
+ expect(menuSource).toContain('aria-busy={remoteSessionBootstrapLoading}');
+ expect(menuSource).toMatch(
+ /<span className="truncate leading-none">\{triggerText\}<\/span>\s*<ChevronDown[\s\S]*?<span\s*aria-hidden="true"\s*className="ml-auto flex h-4 w-4 shrink-0 items-center justify-center"\s*>/,
+ );
+ expect(menuSource).toContain(
+ '<span className="inline-flex animate-spinner motion-reduce:animate-none">',
+ );
+ expect(menuSource).toContain('<Loader2 size={14} strokeWidth={1.8} />');
+ });
+
it('MachineSwitcherMenu 保留门控 / 设备选择 / 远程设置入口', () => {
expect(menuSource).toContain('if (!hasRemote) return null');
expect(menuSource).toContain('MACHINE_ALL');
diff --git a/apps/desktop/src/renderer/features/cc-agent/CCAgentSidebarUpper.tsx b/apps/desktop/src/renderer/features/cc-agent/CCAgentSidebarUpper.tsx
index 25cfba6b8d..84bbd505a4 100644
--- a/apps/desktop/src/renderer/features/cc-agent/CCAgentSidebarUpper.tsx
+++ b/apps/desktop/src/renderer/features/cc-agent/CCAgentSidebarUpper.tsx
@@ -2941,17 +2941,12 @@ function ExpandedView({
partial
/>
)}
- {remoteDeviceDirectoryStatus === 'loading' && (
- <RemoteSidebarLoadNotice kind="devices" status="loading" partial />
- )}
- {remoteSessionBootstrapLoadingDevices.length > 0 && (
- <RemoteSidebarLoadNotice
- kind="tasks"
- status="loading"
- deviceLabel={loadingRemoteDeviceLabel}
- partial
- />
- )}
+ {/*
+ * 远程任务 / 设备目录的 loading 只在上面的「无内容」分支显示。
+ * 这里可能已经有本地或旧的远程快照;把后台重拉提示插进普通文档流会让
+ * 整个侧栏在 loading↔ready 间上下移动,造成可见闪烁。错误提示仍保留
+ * 在列表前,便于用户知道已有内容不是本轮权威结果。
+ */}
<PinnedSection
entries={visiblePinnedEntries}
allKnownProjects={visibleProjectUniverse}
diff --git a/apps/desktop/src/renderer/features/cc-agent/sidebar/MachineSwitcherMenu.tsx b/apps/desktop/src/renderer/features/cc-agent/sidebar/MachineSwitcherMenu.tsx
index 14965c2177..acf69f20a8 100644
--- a/apps/desktop/src/renderer/features/cc-agent/sidebar/MachineSwitcherMenu.tsx
+++ b/apps/desktop/src/renderer/features/cc-agent/sidebar/MachineSwitcherMenu.tsx
@@ -45,6 +45,7 @@ import {
Check,
ChevronDown,
EllipsisVertical,
+ Loader2,
Monitor,
MonitorSmartphone,
} from 'lucide-react';
@@ -66,7 +67,10 @@ import {
MACHINE_ALL,
MACHINE_LOCAL,
} from '@/features/device-link/selectedMachineStore';
-import { useMachineSwitcher } from '@/features/device-link/useMachineSwitcher';
+import {
+ useMachineSwitcher,
+ useRemoteSessionBootstrapLoading,
+} from '@/features/device-link/useMachineSwitcher';
import { MENU_CONTENT_CLASS, MENU_ITEM_CLASS, MENU_SEPARATOR_CLASS } from './menuStyles';
import { useHoverOpenMenu } from './useHoverOpenMenu';
@@ -74,6 +78,9 @@ export function MachineSwitcherMenu(): ReactNode {
const { t } = useTranslation();
const navigate = useNavigate();
const { devices, selectedDeviceId, hasRemote, select, toggle } = useMachineSwitcher();
+ // 机器栏是远程任务读取状态的固定承载点。后台 bootstrap 时只更新这一行,
+ // 不再把 loading 提示插入下方会话列表,避免列表整体上下跳动。
+ const remoteSessionBootstrapLoading = useRemoteSessionBootstrapLoading(selectedDeviceId);
// 「鼠标移上去就展开」:hover 触发行即开、移开即关(受控开合,详见 useHoverOpenMenu;
// 2026-07-12 产品确认要 hover 展开,恢复 d5a8d77c9 之前的交互)。
const { open, onOpenChange, triggerRef, triggerProps, contentProps } = useHoverOpenMenu();
@@ -138,6 +145,7 @@ export function MachineSwitcherMenu(): ReactNode {
ref={triggerRef as Ref<HTMLButtonElement>}
{...triggerProps}
aria-label={`${triggerLabel}: ${triggerText}`}
+ aria-busy={remoteSessionBootstrapLoading}
className={cn(
// 与 SidebarTopNav 的 ROW_CLASS 同款 pill 行:h-8 全宽、图标 meta 灰、
// 文字 foreground、hover 灰底;truncate 兜住过长设备名。
@@ -160,6 +168,16 @@ export function MachineSwitcherMenu(): ReactNode {
strokeWidth={1.8}
className="shrink-0 text-[var(--sidebar-nav-text)]"
/>
+ <span
+ aria-hidden="true"
+ className="ml-auto flex h-4 w-4 shrink-0 items-center justify-center"
+ >
+ {remoteSessionBootstrapLoading && (
+ <span className="inline-flex animate-spinner motion-reduce:animate-none">
+ <Loader2 size={14} strokeWidth={1.8} />
+ </span>
+ )}
+ </span>
</button>
</DropdownMenuTrigger>
<DropdownMenuContent