Consider it done. The open-source AI agent that works out of the box · 想到,就能做到。开源、开箱即用的 AI Agent。
TypeScript agentai-agentai-assistantandroidclaude-codecodexelectroniosllmmacosreact-nativetypescriptwindows
fix(mobile): sync home list on focus and foreground (#3676)
betterkite68c51d7d6a6f
diff --git a/apps/mobile/app/devices/index.tsx b/apps/mobile/app/devices/index.tsxindex 6e4a72e06d..b774d33541 100644--- a/apps/mobile/app/devices/index.tsx+++ b/apps/mobile/app/devices/index.tsx@@ -4,6 +4,7 @@ import {ActivityIndicator,Alert,Animated,+ AppState,Easing,Modal,type NativeScrollEvent,@@ -1187,10 +1188,27 @@ export default function HomeScreen() {// syncInFlight 去重,冷启动时与上线瞬间的两次触发只会实际执行一次。// 首次触发同时等首页列表缓存种入完成(homeListCacheHydrated,AsyncStorage 读一个小 key,毫秒级):// 保证缓存先画、fresh 后覆盖的顺序确定,避免 loadHome 清理下线设备后缓存又把 stale shard 种回去。- useEffect(() => {+ const startSilentHomeSync = useCallback(() => {if (!deviceIdentityCacheReady || !homeListCacheHydrated || !homeViewPreferencesHydrated) return;void loadHome({ visible: false });- }, [connectionEpoch, deviceIdentityCacheReady, homeListCacheHydrated, homeViewPreferencesHydrated, loadHome]);+ }, [deviceIdentityCacheReady, homeListCacheHydrated, homeViewPreferencesHydrated, loadHome]);++ // Android can recreate the activity or resume the JS runtime without a fresh React+ // mount. Foreground is therefore an authoritative trigger alongside the initial mount+ // and reconnect; loadHome single-flights these overlapping cold-start calls.+ useFocusEffect(+ useCallback(() => {+ startSilentHomeSync();+ }, [startSilentHomeSync]),+ );++ useEffect(() => {+ startSilentHomeSync();+ const subscription = AppState.addEventListener('change', (nextState) => {+ if (nextState === 'active') startSilentHomeSync();+ });+ return () => subscription.remove();+ }, [connectionEpoch, startSilentHomeSync]);// 把当前权威设备列表注入 remoteSessionStore,让 store 给所有 useRemoteSessions 消费者(首页项目卡、// 设备详情页)统一算展示用 canonicalDeviceId:re-link 后残留的 stale shard 会话按设备名唯一匹配认领回diff --git a/apps/mobile/src/__tests__/homeDesktopFirst.test.ts b/apps/mobile/src/__tests__/homeDesktopFirst.test.tsindex 5880911dd4..c6e1935853 100644--- a/apps/mobile/src/__tests__/homeDesktopFirst.test.ts+++ b/apps/mobile/src/__tests__/homeDesktopFirst.test.ts@@ -496,7 +496,8 @@ describe('mobile home desktop-first surface', () => {// 只影响首次触发顺序(缓存先画、fresh 后覆盖),不会挡掉任何一次重连刷新。expect(source).not.toContain('homeSessionHydratedRef');expect(source).toContain('!homeViewPreferencesHydrated');- expect(source).toContain('}, [connectionEpoch, deviceIdentityCacheReady, homeListCacheHydrated, homeViewPreferencesHydrated, loadHome]);');+ expect(source).toContain('const startSilentHomeSync = useCallback(() => {');+ expect(source).toContain('}, [connectionEpoch, startSilentHomeSync]);');expect(source).toContain('resolveHomeDeviceSyncIds(');expect(source).toContain('reconcileHomeDeviceSyncScope(syncDeviceIds);');expect(source).toContain('runHomeDeviceSyncBatch(syncRows');@@ -534,6 +535,24 @@ describe('mobile home desktop-first surface', () => {expect(source).not.toContain('refreshControl={<RefreshControl refreshing={loading}');});+ it('starts the silent list sync on Home focus and Android foreground activation', () => {+ const source = readSource('app/devices/index.tsx');+ const silentSync = source.slice(+ source.indexOf('const startSilentHomeSync = useCallback'),+ source.indexOf('// 把当前权威设备列表注入 remoteSessionStore'),+ );++ expect(silentSync).toContain('!deviceIdentityCacheReady');+ expect(silentSync).toContain('!homeListCacheHydrated');+ expect(silentSync).toContain('!homeViewPreferencesHydrated');+ expect(silentSync).toContain('void loadHome({ visible: false });');+ expect(silentSync).toContain('useFocusEffect(');+ expect(silentSync).toContain('startSilentHomeSync();');+ expect(silentSync).toContain("AppState.addEventListener('change'");+ expect(silentSync).toContain("if (nextState === 'active') startSilentHomeSync();");+ expect(silentSync).toContain('}, [connectionEpoch, startSilentHomeSync]);');+ });+it('binds every Home device projection and async continuation to the active account generation', () => {const source = readSource('app/devices/index.tsx');