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): restore browser loading and favicon feedback (#961)

JustinBao5db2fd1cf04c
diff --git a/apps/desktop/src/renderer/features/right-sidebar/hooks/__tests__/useBrowserWebview.test.ts b/apps/desktop/src/renderer/features/right-sidebar/hooks/__tests__/useBrowserWebview.test.ts
index 5099491596..6a394d0b47 100644
--- a/apps/desktop/src/renderer/features/right-sidebar/hooks/__tests__/useBrowserWebview.test.ts
+++ b/apps/desktop/src/renderer/features/right-sidebar/hooks/__tests__/useBrowserWebview.test.ts
@@ -309,6 +309,123 @@ describe('useBrowserWebview', () => {
expect(mockWebview.loadURL).toHaveBeenCalledTimes(BROWSER_NAVIGATION_FUSE_LIMIT + 1);
});
+ it('shows loading immediately on reload and resets after stop-loading', () => {
+ let result: UseBrowserWebviewResult | null = null;
+ render(createElement(HookProbe, {
+ visible: true,
+ onResult: (next) => { result = next; },
+ }));
+
+ act(() => result!.reload());
+ expect(mockWebview.reload).toHaveBeenCalledOnce();
+ expect(result!.isLoading).toBe(true);
+
+ act(() => mockWebview.dispatch('did-stop-loading'));
+ expect(result!.isLoading).toBe(false);
+ });
+
+ it('rolls back optimistic loading when reload throws', () => {
+ mockWebview.reload.mockImplementationOnce(() => {
+ throw new Error('detached');
+ });
+ let result: UseBrowserWebviewResult | null = null;
+ render(createElement(HookProbe, {
+ visible: true,
+ onResult: (next) => { result = next; },
+ }));
+
+ act(() => result!.reload());
+ expect(result!.isLoading).toBe(false);
+ });
+
+ it('leaves loading immediately when the user stops the page', () => {
+ let result: UseBrowserWebviewResult | null = null;
+ render(createElement(HookProbe, {
+ visible: true,
+ onResult: (next) => { result = next; },
+ }));
+
+ act(() => result!.reload());
+ expect(result!.isLoading).toBe(true);
+
+ act(() => result!.stop());
+ expect(mockWebview.stop).toHaveBeenCalledOnce();
+ expect(result!.isLoading).toBe(false);
+ });
+
+ it('distinguishes an unobserved favicon from an explicitly missing favicon', () => {
+ let result: UseBrowserWebviewResult | null = null;
+ render(createElement(HookProbe, {
+ visible: true,
+ onResult: (next) => { result = next; },
+ }));
+
+ expect(result!.favicon).toBeNull();
+
+ act(() => {
+ mockWebview.dispatch('page-favicon-updated', {
+ favicons: ['', 'https://www.taptap.cn/favicon.ico'],
+ });
+ });
+ expect(result!.favicon).toBe('https://www.taptap.cn/favicon.ico');
+
+ act(() => {
+ mockWebview.dispatch('page-favicon-updated', { favicons: [] });
+ });
+ expect(result!.favicon).toBe('');
+ });
+
+ it('does not treat a suppressed stale navigation report as a missing favicon', () => {
+ let result: UseBrowserWebviewResult | null = null;
+ render(createElement(HookProbe, {
+ visible: true,
+ onResult: (next) => { result = next; },
+ }));
+
+ act(() => {
+ mockWebview.dispatch('page-favicon-updated', {
+ favicons: ['https://www.taptap.cn/favicon.ico'],
+ });
+ result!.navigate('https://example.com/');
+ });
+ expect(result!.favicon).toBeNull();
+
+ act(() => {
+ mockWebview.dispatch('did-navigate', { url: 'https://www.taptap.cn/' });
+ });
+ expect(result!.favicon).toBeNull();
+ expect(result!.url).toBe('https://example.com/');
+ });
+
+ it('clears a stale favicon after guest navigation but keeps reload state independent', () => {
+ let result: UseBrowserWebviewResult | null = null;
+ render(createElement(HookProbe, {
+ visible: true,
+ onResult: (next) => { result = next; },
+ }));
+
+ act(() => {
+ mockWebview.dispatch('page-favicon-updated', {
+ favicons: ['https://www.taptap.cn/favicon.ico'],
+ });
+ });
+ expect(result!.favicon).toBe('https://www.taptap.cn/favicon.ico');
+
+ act(() => {
+ mockWebview.dispatch('did-navigate', { url: 'https://example.com/' });
+ });
+ expect(result!.favicon).toBe('');
+
+ act(() => {
+ mockWebview.dispatch('page-favicon-updated', {
+ favicons: ['https://example.com/favicon.ico'],
+ });
+ result!.reload();
+ });
+ expect(result!.favicon).toBe('https://example.com/favicon.ico');
+ expect(result!.isLoading).toBe(true);
+ });
+
it('re-acquires a fresh pool entry when an evicted tab becomes visible again', async () => {
const { browserWebviewPool } = await import('../../lib/browserWebviewPool');
const acquire = vi.mocked(browserWebviewPool.acquire);
diff --git a/apps/desktop/src/renderer/features/right-sidebar/hooks/useBrowserWebview.ts b/apps/desktop/src/renderer/features/right-sidebar/hooks/useBrowserWebview.ts
index d5181d447c..c3f15bdd6e 100644
--- a/apps/desktop/src/renderer/features/right-sidebar/hooks/useBrowserWebview.ts
+++ b/apps/desktop/src/renderer/features/right-sidebar/hooks/useBrowserWebview.ts
@@ -59,8 +59,11 @@ export interface UseBrowserWebviewResult {
url: string;
/** 当前页面 title(`page-title-updated`)。 */
title: string;
- /** 当前页面 favicon URL,无则空串(`page-favicon-updated`)。 */
- favicon: string;
+ /**
+ * 当前页面 favicon URL。null = 当前 webview 代际尚未观测到 favicon;
+ * 空串 = 已明确观测到页面没有 favicon。
+ */
+ favicon: string | null;
/** 正在加载中(`did-start-loading` 翻 true,`did-stop-loading` 翻 false)。 */
isLoading: boolean;
/** webview 导航历史里有"上一页"。 */
@@ -108,7 +111,7 @@ export function useBrowserWebview(
const [wrapper, setWrapper] = useState<HTMLDivElement | null>(null);
const [url, setUrl] = useState('');
const [title, setTitle] = useState('');
- const [favicon, setFavicon] = useState('');
+ const [favicon, setFavicon] = useState<string | null>(null);
const [isLoading, setIsLoading] = useState(false);
const [canGoBack, setCanGoBack] = useState(false);
const [canGoForward, setCanGoForward] = useState(false);
@@ -165,12 +168,13 @@ export function useBrowserWebview(
!isSameNavigationUrl(nextUrl, suppress.targetUrl)
) {
suppressStaleUrlRef.current = null;
- return;
+ return false;
}
suppressStaleUrlRef.current = null;
}
urlRef.current = nextUrl;
setUrl(nextUrl);
+ return true;
}, []);
useEffect(() => {
@@ -195,7 +199,7 @@ export function useBrowserWebview(
suppressStaleUrlRef.current = null;
setUrl('');
setTitle('');
- setFavicon('');
+ setFavicon(null);
setIsLoading(false);
setCanGoBack(false);
setCanGoForward(false);
@@ -232,10 +236,16 @@ export function useBrowserWebview(
const onTitle = (e: Electron.PageTitleUpdatedEvent) => setTitle(e.title);
const onFavicon = (e: Electron.PageFaviconUpdatedEvent) => {
- setFavicon(e.favicons[0] ?? '');
+ setFavicon(e.favicons.find((candidate) => candidate.trim().length > 0) ?? '');
};
const onDidNavigate = (e: Electron.DidNavigateEvent) => {
- setObservedUrl(e.url);
+ const previousUrl = urlRef.current;
+ const accepted = setObservedUrl(e.url);
+ // 网页自身发起的跨页导航没有走 navigate(),必须在提交新 URL 时清掉旧站图标;
+ // 初次 attach / 被抑制的旧 URL 回报都保持 "尚未观测" 语义,避免抹掉持久化 favicon。
+ if (accepted && previousUrl && !isSameNavigationUrl(previousUrl, e.url)) {
+ setFavicon('');
+ }
refreshNav();
};
const onDidNavigateInPage = (e: Electron.DidNavigateInPageEvent) => {
@@ -432,6 +442,9 @@ export function useBrowserWebview(
}
urlRef.current = nextUrl;
setUrl(nextUrl);
+ // 主动导航后旧页 favicon 已不再可信,但这里用 null 表示 "等待新页观测";
+ // BrowserTabBody 会保留持久化 fallback,显式用户导航则由调用方同步清空。
+ setFavicon(null);
setIsLoading(true);
if (!wv) return;
try {
@@ -447,11 +460,30 @@ export function useBrowserWebview(
navigationAttemptsRef.current = [];
navigationFuseTrippedRef.current = false;
setCrash(null);
- webviewRef.current?.reload();
+ setResourceAlert(null);
+ const wv = webviewRef.current;
+ if (!wv) return;
+ // 不等 did-start-loading 才反馈;Electron 事件有异步间隙,用户点击后应立即看到
+ // BrowserChrome 的 loading 动画。调用失败时回滚,避免 UI 永久卡住。
+ setIsLoading(true);
+ try {
+ wv.reload();
+ } catch {
+ setIsLoading(false);
+ }
}, []);
const goBack = useCallback(() => webviewRef.current?.goBack(), []);
const goForward = useCallback(() => webviewRef.current?.goForward(), []);
- const stop = useCallback(() => webviewRef.current?.stop(), []);
+ const stop = useCallback(() => {
+ try {
+ webviewRef.current?.stop();
+ } catch {
+ // detach / crash 窗口内 stop 可能抛;UI 仍应退出 loading,等待后续事件恢复。
+ } finally {
+ // stop 也是用户发起的即时动作;不必再等 did-stop-loading 才恢复刷新按钮。
+ setIsLoading(false);
+ }
+ }, []);
const dismissResourceAlert = useCallback(() => setResourceAlert(null), []);
return {
diff --git a/apps/desktop/src/renderer/features/right-sidebar/plugins/web-browser/BrowserChrome.tsx b/apps/desktop/src/renderer/features/right-sidebar/plugins/web-browser/BrowserChrome.tsx
index 863ee7d2c8..ef492bbd30 100644
--- a/apps/desktop/src/renderer/features/right-sidebar/plugins/web-browser/BrowserChrome.tsx
+++ b/apps/desktop/src/renderer/features/right-sidebar/plugins/web-browser/BrowserChrome.tsx
@@ -216,7 +216,9 @@ export const BrowserChrome = forwardRef<BrowserChromeHandle, BrowserChromeProps>
tooltip={t('rightSidebar.browser.goForward')}
/>
<ChromeIconButton
- icon={isLoading ? XIcon : RotateCw}
+ icon={RotateCw}
+ reducedMotionIcon={isLoading ? XIcon : undefined}
+ spinning={isLoading}
onClick={isLoading ? onStop : onReload}
tooltip={
isLoading
@@ -322,19 +324,29 @@ export const BrowserChrome = forwardRef<BrowserChromeHandle, BrowserChromeProps>
*/
function ChromeIconButton({
icon: Icon,
+ reducedMotionIcon: ReducedMotionIcon,
size = 14,
inlinePill = false,
disabled = false,
active = false,
+ spinning = false,
onClick,
tooltip,
}: {
icon: React.ComponentType<{ size?: number; strokeWidth?: number; className?: string }>;
+ /** reduced-motion 下用静态动作图标表达 loading 状态,避免刷新/空闲态无法区分。 */
+ reducedMotionIcon?: React.ComponentType<{
+ size?: number;
+ strokeWidth?: number;
+ className?: string;
+ }>;
size?: number;
inlinePill?: boolean;
disabled?: boolean;
/** 常亮 active 态(如评论模式进行中):反色底,提示当前处于该工具的模式里。 */
active?: boolean;
+ /** 加载态旋转放在 HTML wrapper 上,避免 SVG 常驻动画触发主线程重绘。 */
+ spinning?: boolean;
onClick: () => void;
tooltip: string;
}) {
@@ -345,6 +357,7 @@ function ChromeIconButton({
onClick={onClick}
title={tooltip}
aria-label={tooltip}
+ aria-busy={spinning || undefined}
className={cn(
'flex shrink-0 items-center justify-center rounded-md transition-colors',
inlinePill ? 'size-[18px]' : 'size-6',
@@ -355,7 +368,25 @@ function ChromeIconButton({
: 'text-sidebar-action-icon hover:bg-sidebar-item-active hover:text-sidebar-item-active-foreground',
)}
>
- <Icon size={size} strokeWidth={2} />
+ {spinning && ReducedMotionIcon ? (
+ <>
+ <span className="inline-flex animate-spinner motion-reduce:hidden">
+ <Icon size={size} strokeWidth={2} />
+ </span>
+ <span className="hidden motion-reduce:inline-flex">
+ <ReducedMotionIcon size={size} strokeWidth={2} />
+ </span>
+ </>
+ ) : (
+ <span
+ className={cn(
+ 'inline-flex',
+ spinning && 'animate-spinner motion-reduce:animate-none',
+ )}
+ >
+ <Icon size={size} strokeWidth={2} />
+ </span>
+ )}
</button>
);
}
diff --git a/apps/desktop/src/renderer/features/right-sidebar/plugins/web-browser/BrowserTabBody.tsx b/apps/desktop/src/renderer/features/right-sidebar/plugins/web-browser/BrowserTabBody.tsx
index d61cb0bf4a..464c1201cb 100644
--- a/apps/desktop/src/renderer/features/right-sidebar/plugins/web-browser/BrowserTabBody.tsx
+++ b/apps/desktop/src/renderer/features/right-sidebar/plugins/web-browser/BrowserTabBody.tsx
@@ -157,8 +157,12 @@ export function BrowserTabBody({ state, ctx, active, shellVisible }: BrowserTabB
}, [browser.title, ctx, state.title]);
useEffect(() => {
- if (browser.favicon === state.favicon) return;
- ctx.patchState({ favicon: browser.favicon || null });
+ // null 表示当前 webview 代际尚未观测到 favicon,不能据此清掉持久化图标;
+ // 空串才是 page-favicon-updated 明确报告 "无图标"。
+ if (browser.favicon === null) return;
+ const nextFavicon = browser.favicon || null;
+ if (nextFavicon === state.favicon) return;
+ ctx.patchState({ favicon: nextFavicon });
}, [browser.favicon, ctx, state.favicon]);
// isAudible 同步:webview audio-state-changed → patchState({isAudible}),
diff --git a/apps/desktop/src/renderer/features/right-sidebar/plugins/web-browser/__tests__/BrowserChrome.test.ts b/apps/desktop/src/renderer/features/right-sidebar/plugins/web-browser/__tests__/BrowserChrome.test.ts
index 8db783017d..73e0fb2424 100644
--- a/apps/desktop/src/renderer/features/right-sidebar/plugins/web-browser/__tests__/BrowserChrome.test.ts
+++ b/apps/desktop/src/renderer/features/right-sidebar/plugins/web-browser/__tests__/BrowserChrome.test.ts
@@ -4,6 +4,7 @@ import { cleanup, fireEvent, render, screen } from '@testing-library/react';
import { afterEach, describe, expect, it, vi } from 'vitest';
import { createElement, createRef } from 'react';
+import tailwindConfig from '../../../../../../../tailwind.config';
import { BrowserChrome, type BrowserChromeHandle } from '../BrowserChrome';
vi.mock('react-i18next', () => ({
@@ -44,7 +45,12 @@ vi.mock('@/components/ui/dropdown-menu', () => {
function renderChrome(
url = 'https://www.taptap.cn/',
- extra: { commentSupported?: boolean } = {},
+ extra: {
+ commentSupported?: boolean;
+ isLoading?: boolean;
+ onReload?: () => void;
+ onStop?: () => void;
+ } = {},
) {
const onNavigate = vi.fn();
const onOpenInSystemBrowser = vi.fn();
@@ -54,12 +60,12 @@ function renderChrome(
createElement(BrowserChrome, {
ref,
url,
- isLoading: false,
+ isLoading: extra.isLoading ?? false,
canGoBack: false,
canGoForward: false,
onNavigate,
- onReload: vi.fn(),
- onStop: vi.fn(),
+ onReload: extra.onReload ?? vi.fn(),
+ onStop: extra.onStop ?? vi.fn(),
onGoBack: vi.fn(),
onGoForward: vi.fn(),
onCaptureScreenshot: vi.fn(),
@@ -67,7 +73,7 @@ function renderChrome(
onToggleComment: vi.fn(),
onOpenInSystemBrowser,
onCopyLink,
- ...extra,
+ commentSupported: extra.commentSupported,
}),
);
return { onNavigate, onOpenInSystemBrowser, onCopyLink, ref };
@@ -106,6 +112,57 @@ describe('BrowserChrome', () => {
).toBeNull();
});
+ it('shows a compositor-friendly refresh animation while loading and stops on click', () => {
+ const onReload = vi.fn();
+ const onStop = vi.fn();
+ renderChrome('https://www.taptap.cn/', {
+ isLoading: true,
+ onReload,
+ onStop,
+ });
+
+ const button = screen.getByRole('button', { name: 'rightSidebar.browser.stop' });
+ const spinner = button.querySelector('span');
+ expect(button.getAttribute('aria-busy')).toBe('true');
+ expect(spinner?.classList.contains('animate-spinner')).toBe(true);
+ expect(spinner?.classList.contains('animate-spin')).toBe(false);
+ expect(spinner?.classList.contains('motion-reduce:hidden')).toBe(true);
+ expect(button.querySelector('.lucide-rotate-cw')).toBeTruthy();
+ expect(
+ button.querySelector('.lucide-x')?.parentElement?.classList.contains(
+ 'motion-reduce:inline-flex',
+ ),
+ ).toBe(true);
+
+ fireEvent.click(button);
+ expect(onStop).toHaveBeenCalledOnce();
+ expect(onReload).not.toHaveBeenCalled();
+ });
+
+ it('keeps the idle refresh icon static and reloads on click', () => {
+ const onReload = vi.fn();
+ const onStop = vi.fn();
+ renderChrome('https://www.taptap.cn/', { onReload, onStop });
+
+ const button = screen.getByRole('button', { name: 'rightSidebar.browser.reload' });
+ expect(button.hasAttribute('aria-busy')).toBe(false);
+ expect(button.querySelector('span')?.classList.contains('animate-spinner')).toBe(false);
+
+ fireEvent.click(button);
+ expect(onReload).toHaveBeenCalledOnce();
+ expect(onStop).not.toHaveBeenCalled();
+ });
+
+ it('routes the refresh spinner through the approved semantic cycle token', () => {
+ const animation = (
+ tailwindConfig.theme?.extend?.animation as Record<string, string> | undefined
+ )?.spinner;
+
+ expect(animation).toContain('var(--motion-spinner-cycle, 1000ms)');
+ expect(animation).not.toContain('--motion-enter');
+ expect(animation).not.toContain('spin 1s');
+ });
+
it('fires open-in-system-browser and copy-link from the more menu when the link is valid', () => {
const { onOpenInSystemBrowser, onCopyLink } = renderChrome();
diff --git a/apps/desktop/src/renderer/features/right-sidebar/plugins/web-browser/__tests__/BrowserTabBody.navigation.test.ts b/apps/desktop/src/renderer/features/right-sidebar/plugins/web-browser/__tests__/BrowserTabBody.navigation.test.ts
index 6ebbc56981..af8b959679 100644
--- a/apps/desktop/src/renderer/features/right-sidebar/plugins/web-browser/__tests__/BrowserTabBody.navigation.test.ts
+++ b/apps/desktop/src/renderer/features/right-sidebar/plugins/web-browser/__tests__/BrowserTabBody.navigation.test.ts
@@ -70,6 +70,11 @@ function renderBrowserTab(
stateUrl: string,
patchState = vi.fn(),
active = true,
+ statePatch: Partial<{
+ title: string;
+ favicon: string | null;
+ isAudible: boolean;
+ }> = {},
): ReactElement {
const ctx: TabKindHostContext = {
tabId: 'tab-browser',
@@ -88,6 +93,7 @@ function renderBrowserTab(
title: '',
favicon: null,
isAudible: false,
+ ...statePatch,
},
});
}
@@ -226,6 +232,34 @@ describe('BrowserTabBody navigation', () => {
expect(browserNavigate).not.toHaveBeenCalled();
});
+ it('keeps a persisted favicon while the new webview has not observed one yet', () => {
+ browserState = makeBrowserState({ favicon: null });
+ const patchState = vi.fn();
+
+ render(renderBrowserTab(
+ 'https://www.taptap.cn/',
+ patchState,
+ true,
+ { favicon: 'https://www.taptap.cn/favicon.ico' },
+ ));
+
+ expect(patchState).not.toHaveBeenCalledWith({ favicon: null });
+ });
+
+ it('clears a persisted favicon after the webview explicitly reports none', () => {
+ browserState = makeBrowserState({ favicon: '' });
+ const patchState = vi.fn();
+
+ render(renderBrowserTab(
+ 'https://www.taptap.cn/',
+ patchState,
+ true,
+ { favicon: 'https://www.taptap.cn/favicon.ico' },
+ ));
+
+ expect(patchState).toHaveBeenCalledWith({ favicon: null });
+ });
+
it('does not run browser shortcuts while an editable target has focus', () => {
const reload = vi.fn();
const goBack = vi.fn();
diff --git a/apps/desktop/src/renderer/features/right-sidebar/plugins/web-browser/__tests__/WebBrowserTabPillIcon.test.tsx b/apps/desktop/src/renderer/features/right-sidebar/plugins/web-browser/__tests__/WebBrowserTabPillIcon.test.tsx
new file mode 100644
index 0000000000..f1cabdb397
--- /dev/null
+++ b/apps/desktop/src/renderer/features/right-sidebar/plugins/web-browser/__tests__/WebBrowserTabPillIcon.test.tsx
@@ -0,0 +1,55 @@
+// @vitest-environment jsdom
+
+import { cleanup, fireEvent, render } from '@testing-library/react';
+import { afterEach, describe, expect, it } from 'vitest';
+
+import { WebBrowserTabPillIcon, type WebBrowserState } from '../index';
+
+function browserState(favicon: string | null): WebBrowserState {
+ return {
+ url: 'https://example.com/',
+ title: 'Example',
+ favicon,
+ isAudible: false,
+ };
+}
+
+describe('WebBrowserTabPillIcon', () => {
+ afterEach(cleanup);
+
+ it('renders the observed page favicon', () => {
+ const view = render(
+ <WebBrowserTabPillIcon state={browserState('https://example.com/favicon.ico')} />,
+ );
+
+ const image = view.container.querySelector('img');
+ expect(image?.getAttribute('src')).toBe('https://example.com/favicon.ico');
+ expect(view.container.querySelector('.lucide-globe')).toBeNull();
+ });
+
+ it('falls back to Globe when the favicon cannot load', () => {
+ const view = render(
+ <WebBrowserTabPillIcon state={browserState('https://example.com/missing.ico')} />,
+ );
+
+ fireEvent.error(view.container.querySelector('img')!);
+
+ expect(view.container.querySelector('img')).toBeNull();
+ expect(view.container.querySelector('.lucide-globe')).toBeTruthy();
+ });
+
+ it('retries with a new favicon URL after an earlier URL failed', () => {
+ const view = render(
+ <WebBrowserTabPillIcon state={browserState('https://example.com/missing.ico')} />,
+ );
+ fireEvent.error(view.container.querySelector('img')!);
+
+ view.rerender(
+ <WebBrowserTabPillIcon state={browserState('https://example.com/favicon-v2.ico')} />,
+ );
+
+ expect(view.container.querySelector('img')?.getAttribute('src'))
+ .toBe('https://example.com/favicon-v2.ico');
+ expect(view.container.querySelector('.lucide-globe')).toBeNull();
+ });
+});
diff --git a/apps/desktop/src/renderer/features/right-sidebar/plugins/web-browser/index.tsx b/apps/desktop/src/renderer/features/right-sidebar/plugins/web-browser/index.tsx
index 1b13ec4dad..4d915cbd96 100644
--- a/apps/desktop/src/renderer/features/right-sidebar/plugins/web-browser/index.tsx
+++ b/apps/desktop/src/renderer/features/right-sidebar/plugins/web-browser/index.tsx
@@ -17,6 +17,7 @@
import { Globe, Volume2 } from 'lucide-react';
import type { TFunction } from 'i18next';
+import { useState } from 'react';
import { cn } from '@/lib/utils';
@@ -67,17 +68,11 @@ function WebBrowserTabPillTitle({
* tab pill 行为一致 —— 用户能从图标一眼看出哪个 tab 在发声)。
* favicon onError(404 / 取不到)→ 也走 fallback,不让破图占位。
*/
-function WebBrowserTabPillIcon({ state }: { state: WebBrowserState }) {
+export function WebBrowserTabPillIcon({ state }: { state: WebBrowserState }) {
const base = state.favicon ? (
- <img
+ <FaviconImage
+ key={state.favicon}
src={state.favicon}
- alt=""
- width={13}
- height={13}
- onError={(e) => {
- (e.currentTarget as HTMLImageElement).style.visibility = 'hidden';
- }}
- style={{ objectFit: 'contain' }}
/>
) : (
<Globe size={13} />
@@ -98,6 +93,27 @@ function WebBrowserTabPillIcon({ state }: { state: WebBrowserState }) {
);
}
+/**
+ * favicon URL 可能来自独立 webview partition、临时 blob 或需要登录态的资源。
+ * host renderer 加载失败时保留稳定的 Globe fallback;src 变化通过 key 重建本组件,
+ * 让新站点图标拥有独立的错误状态。
+ */
+function FaviconImage({ src }: { src: string }) {
+ const [failed, setFailed] = useState(false);
+ if (failed) return <Globe size={13} />;
+ return (
+ <img
+ src={src}
+ alt=""
+ width={13}
+ height={13}
+ draggable={false}
+ onError={() => setFailed(true)}
+ style={{ objectFit: 'contain' }}
+ />
+ );
+}
+
const plugin: TabKindPlugin<WebBrowserState> = {
kind: 'web-browser',
menu: {
diff --git a/apps/desktop/src/renderer/styles/globals.css b/apps/desktop/src/renderer/styles/globals.css
index 3515637cb8..efb5cbce60 100644
--- a/apps/desktop/src/renderer/styles/globals.css
+++ b/apps/desktop/src/renderer/styles/globals.css
@@ -47,13 +47,14 @@
--text-28: 28px;
/* Motion token(全局动效档位,规范见 DESIGN.md §14.4):新增过渡/动画一律
- 引用这些 token,不要再各处硬编码时长和 cubic-bezier。5 档时长 + 3 条
- 曲线,与三档圆角同一哲学——档位之外的值先过设计评审再加。 */
+ 引用这些 token,不要再各处硬编码时长和 cubic-bezier。5 档交互时长 +
+ spinner 语义循环例外 + 3 条曲线,与三档圆角同一哲学。 */
--motion-instant: 80ms; /* hover 即时反馈、轻浮层退场 */
--motion-fast: 150ms; /* 颜色/透明度状态切换、轻浮层入场(§14.4 功能性过渡上限) */
--motion-base: 200ms; /* 尺寸变化:展开折叠、面板收展 */
--motion-enter: 250ms; /* 重浮层(弹窗)入场 */
--motion-exit: 150ms; /* 重浮层(弹窗)退场 */
+ --motion-spinner-cycle: 1000ms; /* 功能性 loading spinner 完整一圈(§14.4 窄例外) */
--motion-ease-out: cubic-bezier(0.16, 1, 0.3, 1); /* 入场/展开 */
--motion-ease-in: cubic-bezier(0.4, 0, 1, 1); /* 退场 */
--motion-ease-move: cubic-bezier(0.4, 0, 0.2, 1); /* 位置/尺寸插值 */
@@ -137,6 +138,11 @@
--motion-base: 0ms;
--motion-enter: 0ms;
--motion-exit: 0ms;
+ --motion-spinner-cycle: 0ms;
+ }
+
+ [class*='animate-spinner'] {
+ animation: none !important;
}
.animate-confirm-overlay-in,
@@ -944,6 +950,7 @@ body.resizing-pane [data-ghost-webview] {
[data-app-hidden='true'] .agent-island-mascot-key,
[data-app-hidden='true'] .agent-island-mascot-eyes,
[data-app-hidden='true'] .agent-island-mascot-sparkle,
+[data-app-hidden='true'] [class*='animate-spinner'],
[data-app-hidden='true'] [class*='animate-spin'],
[data-app-hidden='true'] [class*='animate-pulse'],
[data-app-hidden='true'] [class*='infinite'],
diff --git a/apps/desktop/tailwind.config.ts b/apps/desktop/tailwind.config.ts
index 4f4ce0e787..ae128fddee 100644
--- a/apps/desktop/tailwind.config.ts
+++ b/apps/desktop/tailwind.config.ts
@@ -121,6 +121,10 @@ const config: Config = {
},
},
animation: {
+ // 功能性 loading spinner 使用 DESIGN.md §14.4 明确登记的语义循环 token;
+ // 不复用 Tailwind animate-spin 的硬编码 1s,也不耦合 enter/exit 交互档位。
+ spinner:
+ 'spin var(--motion-spinner-cycle, 1000ms) linear infinite',
// float-out 需要 forwards:Radix 等 animationend 才卸载,fill 不驻留
// 会在动画结束到卸载之间闪回原状。
'float-in':
diff --git a/apps/mobile/src/__tests__/themeTokens.test.ts b/apps/mobile/src/__tests__/themeTokens.test.ts
index 340e475655..96e2d46fe6 100644
--- a/apps/mobile/src/__tests__/themeTokens.test.ts
+++ b/apps/mobile/src/__tests__/themeTokens.test.ts
@@ -5,6 +5,7 @@ import {
iconSize,
lightColors,
lineHeight,
+ motionDuration,
palettes,
textStyles,
typeScale,
@@ -43,6 +44,10 @@ describe('theme tokens', () => {
expect(palettes.dark).toBe(darkColors);
});
+ it('spinner 语义循环例外与 DESIGN.md §14.4 保持一致', () => {
+ expect(motionDuration.spinnerCycle).toBe(1000);
+ });
+
it('每个颜色 token 都是非空字符串(login 登录皮嵌套组下钻)', () => {
for (const palette of [lightColors, darkColors]) {
for (const [key, value] of Object.entries(palette)) {
diff --git a/apps/mobile/src/theme/tokens.ts b/apps/mobile/src/theme/tokens.ts
index 0797cf748e..21b2c1b816 100644
--- a/apps/mobile/src/theme/tokens.ts
+++ b/apps/mobile/src/theme/tokens.ts
@@ -652,6 +652,7 @@ export const loginSizes = {
/**
* Motion token(全局动效档位,ms)——与桌面端 DESIGN.md §14.4 的 --motion-* 同名
* 同值,双端同构。新增动效一律引用这些档位,不要在组件里硬编码时长。
+ * spinnerCycle 是功能性 loading spinner 的语义循环例外,不是第六档交互时长。
*/
export const motionDuration = {
/** hover / 即时反馈、轻浮层退场 */
@@ -664,6 +665,8 @@ export const motionDuration = {
enter: 250,
/** 重浮层(弹窗 / sheet)退场 */
exit: 150,
+ /** 功能性 loading spinner 完整一圈(§14.4 窄例外) */
+ spinnerCycle: 1000,
} as const;
/**
diff --git a/docs/design-rules/DESIGN.md b/docs/design-rules/DESIGN.md
index 080e8e5b7b..41098f80e4 100644
--- a/docs/design-rules/DESIGN.md
+++ b/docs/design-rules/DESIGN.md
@@ -547,7 +547,7 @@ Applies to submit-on-Enter fields: the chat composer, goal input, ask input, etc
#### Motion tokens (the only tier source)
-Global tokens live in `:root` of `apps/desktop/src/renderer/styles/globals.css`; mobile (`apps/mobile`) mirrors same-name same-value constants in `src/theme/tokens.ts` (dual-platform isomorphism, same policy as color tokens, landing with the mobile motion overhaul). **New transitions/animations must reference tokens — no hardcoded durations or cubic-beziers**; 5 duration tiers + 3 curves, the same philosophy as the §5 three-tier radius. Values outside the tiers require design review first.
+Global tokens live in `:root` of `apps/desktop/src/renderer/styles/globals.css`; mobile (`apps/mobile`) mirrors same-name same-value constants in `src/theme/tokens.ts` (dual-platform isomorphism, same policy as color tokens, landing with the mobile motion overhaul). **New transitions/animations must reference tokens — no hardcoded durations or cubic-beziers**; 5 interaction-duration tiers + 3 curves, the same philosophy as the §5 three-tier radius. Values outside the tiers require design review first. The single semantic loop-cycle exception is recorded directly below.
| Token | Value | Use |
|---|---|---|
@@ -560,6 +560,14 @@ Global tokens live in `:root` of `apps/desktop/src/renderer/styles/globals.css`;
| `--motion-ease-in` | `cubic-bezier(0.4, 0, 1, 1)` | Exit |
| `--motion-ease-move` | `cubic-bezier(0.4, 0, 0.2, 1)` | Position/size interpolation |
+**Semantic loop-cycle exception:** `--motion-spinner-cycle` = `1000ms` is the
+full-turn duration for functional loading spinners. It is not a sixth interaction
+tier and must not be used for enter/exit, hover, resize, or decorative motion.
+Spinner rotation remains linear, transform-only, mounted on an HTML wrapper, and
+must become static under reduced motion. This exception keeps loading rotation
+readable without coupling it to dialog timing or copying a hardcoded Tailwind
+default into components.
+
#### Semantics → motion prototypes (one semantic, one motion, app-wide)
| Semantic | Spec | Reference implementation |
@@ -571,6 +579,7 @@ Global tokens live in `:root` of `apps/desktop/src/renderer/styles/globals.css`;
| Press | `active:scale-[0.98]` (all interactive pills/buttons) | ConfirmDialog buttons |
| Done | **the app's only sanctioned overshoot** (`status-done-pop`) | `globals.css` |
| Running | Opacity breathing; must sit on an HTML wrapper (`docs/dev-rules/engineering-conventions.md` §7) | `session-breathing` |
+| Loading spinner | `animate-spinner` (`--motion-spinner-cycle`, linear full turn); HTML wrapper only, static under reduced motion | `tailwind.config.ts` |
| Hover / state colors | `transition-colors`, ≤ fast (150ms) | App-wide status quo |
| Container transform (chip grows into panel) | 220ms — see the dedicated category below (explicit exception) | Composer permission/model selectors |