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(mobile): wait for all remote shards before loading

MagicLizib241a00251c2
diff --git a/apps/mobile/src/__tests__/useRemoteResourceList.test.tsx b/apps/mobile/src/__tests__/useRemoteResourceList.test.tsx
index 4c4af79654..6c8f3a3a5f 100644
--- a/apps/mobile/src/__tests__/useRemoteResourceList.test.tsx
+++ b/apps/mobile/src/__tests__/useRemoteResourceList.test.tsx
@@ -208,6 +208,7 @@ it('commits and persists a successful host before a slow sibling settles', async
expect(result.items.map(row => row.item.ref.id)).toEqual(['fresh-mac']);
expect(result.isOnline(targets[0])).toBe(true);
expect(result.syncing).toBe(true);
+ expect(result.loading).toBe(true);
expect(h.persist).toHaveBeenCalledWith('owner', 'teammates', result.items);
await act(async () => finish({ items: [] }));
expect(result.syncing).toBe(false);
diff --git a/apps/mobile/src/session/useRemoteResourceList.ts b/apps/mobile/src/session/useRemoteResourceList.ts
index 352338e526..fa96af2a70 100644
--- a/apps/mobile/src/session/useRemoteResourceList.ts
+++ b/apps/mobile/src/session/useRemoteResourceList.ts
@@ -99,7 +99,7 @@ export function useRemoteResourceList(collectionId: string, targets: readonly Re
key: JSON.stringify([host.deviceId, item.ref.collectionId, item.ref.kind, item.ref.id]) }));
setState(old => ({ ...old,
items: mergeRemoteCollectionHostShards(old.items, next, new Set([host.deviceId]), targets),
- replies: { ...old.replies, [host.deviceId]: connectionEpoch }, settled: true,
+ replies: { ...old.replies, [host.deviceId]: connectionEpoch },
}));
} catch (error) {
if (!current()) return;
@@ -129,10 +129,10 @@ export function useRemoteResourceList(collectionId: string, targets: readonly Re
// Persist after commit, never from a React state updater (which may be replayed).
useEffect(() => {
- if (state.binding !== binding || !state.settled || hydrated !== binding) return;
+ if (state.binding !== binding || (!state.settled && Object.keys(state.replies).length === 0) || hydrated !== binding) return;
writeRemoteCollectionCache(owner, collectionId, state.items);
void cacheRemoteResourceItems(user?.id ?? '', collectionId, state.items);
- }, [binding, collectionId, hydrated, owner, state.items, state.settled, state.binding, user?.id]);
+ }, [binding, collectionId, hydrated, owner, state.items, state.replies, state.settled, state.binding, user?.id]);
useFocusEffect(useCallback(() => {
if (!enabled) return;
const start = () => {