Consider it done. The open-source AI agent that works out of the box · 想到,就能做到。开源、开箱即用的 AI Agent。
TypeScript agentai-agentai-assistantandroidclaude-codecodexelectroniosllmmacosreact-nativetypescriptwindows
fix(mobile): preserve the task page and sidebar when switching tasks
Dash70686d2c604e
diff --git a/apps/mobile/app/sessions/[sessionId].tsx b/apps/mobile/app/sessions/[sessionId].tsxindex f0c3a2fe4d..926d792f3a 100644--- a/apps/mobile/app/sessions/[sessionId].tsx+++ b/apps/mobile/app/sessions/[sessionId].tsx@@ -1026,7 +1026,7 @@ export default function SessionScreen() {?? remoteSessionStore.getSessionDeviceId(sessionId) ?? '';const session = useRemoteSessionDetail(deviceId, sessionId);return (- <SideChatTaskBoundary key={`${deviceId}:${sessionId}`} deviceId={deviceId}+ <SideChatTaskBoundary deviceId={deviceId}sessionId={sessionId} enabled={session?.source === 'side-chat'}><CindyMakeSessionGate sessionId={sessionId} deviceId={deviceId || undefined} ownsSessionSubscription><SessionScreenContent />diff --git a/apps/mobile/docs/navigation-and-composer.md b/apps/mobile/docs/navigation-and-composer.mdindex 43ab169abb..e7770747bc 100644--- a/apps/mobile/docs/navigation-and-composer.md+++ b/apps/mobile/docs/navigation-and-composer.md@@ -20,6 +20,7 @@- 伙伴对话:左上角为返回(回到伙伴列表);Duo 系统栏已有返回时保留侧栏按钮,不出现两个返回。- Duo 等宽屏任务页可拖动中间把手调整两栏:列表宽度限制在 240–420pt,并为正文保留至少 400pt;真实折痕划分的两栏不允许移动。宽度在当前窗口内跨任务和旋转保留,不写入持久设置。- iOS 首页列表留在自己的原生路由内,进入任务后仍可供返回动画显示;常驻侧栏独立保留列表内容,拖动分栏时不叠加尺寸动画。抽屉页面卸载时只撤销自己发布的内容,旧页面的清理不影响新页面,下一任务测量前不显示失效内容。系统顶栏已计入安全区时,磨砂高度直接采用原生测量值。+- 侧栏切换任务沿用当前页面,不用任务 ID 重建整页,保留侧栏标题和测量槽。侧聊删除保护在边界内部按电脑及任务身份重置;旧订阅的迟到删除不能隐藏或退出新任务。- 设置等整页滚动的二级页:顶栏透明、系统柔和边缘,内容滚到顶栏和底部指示条下面,无硬分界(设置、语音词典、账号注销、伙伴私聊、共享任务管理、资源列表);设备详情只去掉底部色带。## 已知未完成diff --git a/apps/mobile/src/__tests__/sideChatTaskBoundary.test.tsx b/apps/mobile/src/__tests__/sideChatTaskBoundary.test.tsxindex 1b6e50db94..090bd7eab8 100644--- a/apps/mobile/src/__tests__/sideChatTaskBoundary.test.tsx+++ b/apps/mobile/src/__tests__/sideChatTaskBoundary.test.tsx@@ -1,7 +1,10 @@// @vitest-environment jsdomimport * as React from 'react';+import { readFileSync } from 'node:fs';+import { resolve } from 'node:path';import { act } from 'react';import { createRoot } from 'react-dom/client';+import ts from 'typescript';import { afterEach, beforeEach, describe, expect, it, vi } from 'vitest';import { SideChatTaskBoundary } from '../session/SideChatTaskBoundary';@@ -12,6 +15,7 @@ const state = vi.hoisted(() => ({replace: vi.fn(),dismissKeyboard: vi.fn(),listeners: new Set<(deviceId: string, sessionId: string) => void>(),+ route: { deviceId: 'host', sessionId: 'child' },}));vi.mock('react-native', () => ({Keyboard: { dismiss: state.dismissKeyboard },@@ -29,6 +33,32 @@ vi.mock('../session/remoteSessionStore', () => ({},}));+// Execute the actual route wrapper (without loading the native editor tree).+// Boundary-only tests cannot catch a task key added by its caller.+const source = ts.createSourceFile('session.tsx', readFileSync(+ resolve(process.cwd(), 'app/sessions/[sessionId].tsx'), 'utf8',+), ts.ScriptTarget.Latest, true, ts.ScriptKind.TSX);+const page = source.statements.find((node): node is ts.FunctionDeclaration =>+ ts.isFunctionDeclaration(node) && node.name?.text === 'SessionScreen');+if (!page?.body) throw new Error('SessionScreen not found');+const compiledRoute = ts.transpileModule(`function SessionScreen() ${page.body.getText(source)}`, {+ compilerOptions: { jsx: ts.JsxEmit.React, target: ts.ScriptTarget.ES2022 },+}).outputText;+const SessionRoute = new Function('bindings', `+ const { React, useLocalSearchParams, readRouteParam, remoteSessionStore,+ useRemoteSessionDetail, SideChatTaskBoundary, CindyMakeSessionGate, SessionScreenContent } = bindings;+ ${compiledRoute}+ return SessionScreen;+`)({+ React, SideChatTaskBoundary,+ useLocalSearchParams: () => state.route,+ readRouteParam: (value: string) => value,+ remoteSessionStore: { getSessionDeviceId: () => 'host' },+ useRemoteSessionDetail: () => ({ source: 'local' }),+ CindyMakeSessionGate: ({ children }: { children: React.ReactNode }) => children,+ SessionScreenContent: () => <textarea aria-label="Message" />,+}) as React.ComponentType;+// Unit, black-box regression 2026-10-20: a deleted follow-up kept its editor.// Picker/count tests do not mount this route boundary. Minimal input: an own// removal signal, with the route focused or hidden. Full pages must unmount the@@ -36,8 +66,8 @@ vi.mock('../session/remoteSessionStore', () => ({describe('side chat task lifecycle', () => {let host: HTMLDivElement;let root: ReturnType<typeof createRoot>;- const render = (enabled = true) => act(() => root.render(- <SideChatTaskBoundary deviceId="host" sessionId="child" enabled={enabled}>+ const render = (enabled = true, sessionId = 'child', deviceId = 'host') => act(() => root.render(+ <SideChatTaskBoundary deviceId={deviceId} sessionId={sessionId} enabled={enabled}><textarea aria-label="Message" /></SideChatTaskBoundary>,));@@ -101,4 +131,54 @@ describe('side chat task lifecycle', () => {expect(state.back).not.toHaveBeenCalled();expect(state.replace).toHaveBeenCalledExactlyOnceWith('/');});++ // Unit regression 2026-10-24: task-keyed deletion protection remounted the+ // whole page and sidebar on every switch. Existing tests only used one task.+ // The boundary must retain live children yet isolate removal across scopes.+ it('keeps the mounted page when switching ordinary tasks and computers', () => {+ const renderRoute = (sessionId: string, deviceId = 'host') => {+ state.route = { deviceId, sessionId };+ act(() => root.render(<SessionRoute />));+ };+ renderRoute('child');+ const editor = host.querySelector('textarea')!;+ renderRoute('next');+ expect(host.querySelector('textarea')).toBe(editor);+ renderRoute('next', 'other-host');+ expect(host.querySelector('textarea')).toBe(editor);+ expect(state.back).not.toHaveBeenCalled();+ });++ it.each([+ ['next', 'host'],+ ['child', 'other-host'],+ ])('does not carry a hidden deletion into %s on %s', (sessionId, deviceId) => {+ state.focused = false;+ render();+ remove();+ expect(host.querySelector('textarea')).toBeNull();+ state.focused = true;+ render(true, sessionId, deviceId);+ expect(host.querySelector('textarea')).not.toBeNull();+ expect(state.back).not.toHaveBeenCalled();+ remove(deviceId, sessionId);+ expect(host.querySelector('textarea')).toBeNull();+ expect(state.back).toHaveBeenCalledTimes(1);+ });++ it('returns once per removed task while ignoring a retired subscription callback', () => {+ render();+ const lateRemoval = [...state.listeners][0]!;+ remove();+ expect(state.back).toHaveBeenCalledTimes(1);+ render(true, 'next');+ const editor = host.querySelector('textarea');+ expect(editor).not.toBeNull();+ act(() => lateRemoval('host', 'child'));+ expect(host.querySelector('textarea')).toBe(editor);+ remove('host', 'next');+ remove('host', 'next');+ expect(state.back).toHaveBeenCalledTimes(2);+ expect(host.querySelector('textarea')).toBeNull();+ });});diff --git a/apps/mobile/src/session/SideChatTaskBoundary.tsx b/apps/mobile/src/session/SideChatTaskBoundary.tsxindex a7cc56fe0b..76f1afd773 100644--- a/apps/mobile/src/session/SideChatTaskBoundary.tsx+++ b/apps/mobile/src/session/SideChatTaskBoundary.tsx@@ -15,20 +15,29 @@ export function SideChatTaskBoundary({ children, deviceId, sessionId, enabled }:}) {const router = useRouter();const focused = useIsFocused();- const [removed, setRemoved] = useState(false);- const returned = useRef(false);+ const scope = JSON.stringify([deviceId, sessionId]);+ const [removal, setRemoval] = useState({ scope, removed: false });+ // Reset only deletion state when params change. Keying this boundary by task+ // would also remount the page, its sidebar header and its measuring slot.+ if (removal.scope !== scope) setRemoval({ scope, removed: false });+ const removed = removal.scope === scope && removal.removed;+ const returned = useRef<typeof removal | null>(null);useEffect(() => {if (!enabled) return;- return remoteSessionStore.onSessionRemoved((ownerDeviceId, removedSessionId) => {- if (ownerDeviceId === deviceId && removedSessionId === sessionId) setRemoved(true);+ let active = true;+ const unsubscribe = remoteSessionStore.onSessionRemoved((ownerDeviceId, removedSessionId) => {+ if (!active || ownerDeviceId !== deviceId || removedSessionId !== sessionId) return;+ setRemoval(current => current.scope === scope && !current.removed+ ? { scope, removed: true } : current);});- }, [deviceId, enabled, sessionId]);+ return () => { active = false; unsubscribe(); };+ }, [deviceId, enabled, scope, sessionId]);useEffect(() => {// A hidden route waits for focus so deletion never pops a different screen.- if (!focused || !removed || returned.current) return;- returned.current = true;+ if (!focused || !removed || returned.current === removal) return;+ returned.current = removal;Keyboard.dismiss();goBackGuarded(router);- }, [focused, removed, router]);+ }, [focused, removal, removed, router]);return removed ? null : children;}