Consider it done. The open-source AI agent that works out of the box · 想到,就能做到。开源、开箱即用的 AI Agent。
TypeScript agentai-agentai-assistantandroidclaude-codecodexelectroniosllmmacosreact-nativetypescriptwindows
fix(motion): sync stream fade across chat windows
davidc68aa03736ba
diff --git a/apps/desktop/src/renderer/hooks/__tests__/useStreamFadePreference.test.ts b/apps/desktop/src/renderer/hooks/__tests__/useStreamFadePreference.test.tsindex 4cf124aac3..6dca086a03 100644--- a/apps/desktop/src/renderer/hooks/__tests__/useStreamFadePreference.test.ts+++ b/apps/desktop/src/renderer/hooks/__tests__/useStreamFadePreference.test.ts@@ -68,4 +68,21 @@ describe('useStreamFadePreference', () => {act(() => pref.result.current.setPreference('off'));expect(enabled.result.current).toBe(false);});++ it('useStreamFadeEnabled tracks storage changes without the settings hook mounted', () => {+ const enabled = renderHook(() => useStreamFadeEnabled());+ expect(enabled.result.current).toBe(false);++ act(() => {+ localStorage.setItem(KEY, 'on');+ window.dispatchEvent(new StorageEvent('storage', { key: KEY, newValue: 'on' }));+ });+ expect(enabled.result.current).toBe(true);++ act(() => {+ localStorage.removeItem(KEY);+ window.dispatchEvent(new StorageEvent('storage', { key: KEY, newValue: null }));+ });+ expect(enabled.result.current).toBe(false);+ });});diff --git a/apps/desktop/src/renderer/hooks/useStreamFadePreference.ts b/apps/desktop/src/renderer/hooks/useStreamFadePreference.tsindex c6d3a8984c..dae60dd802 100644--- a/apps/desktop/src/renderer/hooks/useStreamFadePreference.ts+++ b/apps/desktop/src/renderer/hooks/useStreamFadePreference.ts@@ -45,16 +45,39 @@ export function getStreamFadePreference(): StreamFadePreference {}const listeners = new Set<() => void>();+let storageSubscribed = false;++function notifyListeners(): void {+ listeners.forEach((fn) => fn());+}++function onStorage(e: StorageEvent): void {+ if (e.key !== STORAGE_KEY) return;+ memoryValue = parsePreference(e.newValue) ?? DEFAULT_PREFERENCE;+ notifyListeners();+}++function subscribe(listener: () => void): () => void {+ listeners.add(listener);+ if (!storageSubscribed) {+ window.addEventListener('storage', onStorage);+ storageSubscribed = true;+ }+ return () => {+ listeners.delete(listener);+ if (listeners.size === 0 && storageSubscribed) {+ window.removeEventListener('storage', onStorage);+ storageSubscribed = false;+ }+ };+}/** 消息渲染侧的轻量订阅:只关心 boolean,设置页切换后即时重渲。 */export function useStreamFadeEnabled(): boolean {const [enabled, setEnabled] = useState(() => getStreamFadePreference() === 'on');useEffect(() => {const sync = () => setEnabled(getStreamFadePreference() === 'on');- listeners.add(sync);- return () => {- listeners.delete(sync);- };+ return subscribe(sync);}, []);return enabled;}@@ -80,22 +103,12 @@ export function useStreamFadePreference(): {} catch {// localStorage 不可用——内存 SoT 已生效;仅跨窗口同步缺失。}- listeners.forEach((fn) => fn());+ notifyListeners();}, []);useEffect(() => {const sync = () => setState(getStreamFadePreference());- listeners.add(sync);- const onStorage = (e: StorageEvent) => {- if (e.key !== STORAGE_KEY) return;- memoryValue = parsePreference(e.newValue) ?? DEFAULT_PREFERENCE;- sync();- };- window.addEventListener('storage', onStorage);- return () => {- listeners.delete(sync);- window.removeEventListener('storage', onStorage);- };+ return subscribe(sync);}, []);return { preference, isCustomized: preference !== DEFAULT_PREFERENCE, setPreference };@@ -105,4 +118,8 @@ export function useStreamFadePreference(): {export function _resetStreamFadePreferenceForTests(): void {memoryValue = null;listeners.clear();+ if (storageSubscribed) {+ window.removeEventListener('storage', onStorage);+ storageSubscribed = false;+ }}