Skip to content

🤯 LobeHub - Super-Agents on Your Team. Add super-agents to the chats your team already uses.They take on work by themselves and get better every week.

🐛 fix(device): bump local-replica to 0.1.1 so a late linked-PR lookup no longer crashes (#21960)

Lobehub Coder671738f070b8
diff --git a/package.json b/package.json
index 1fb7201c291..a3989b23972 100644
--- a/package.json
+++ b/package.json
@@ -410,7 +410,7 @@
"langfuse": "^3.38.20",
"langfuse-core": "^3.38.20",
"lexical": "0.42.0",
- "local-replica": "^0.0.4",
+ "local-replica": "^0.1.1",
"lucide-react": "^1.31.0",
"mammoth": "^1.12.1",
"marked": "^17.0.6",
diff --git a/src/store/device/gitReview/store.test.ts b/src/store/device/gitReview/store.test.ts
index c0f40d6a23b..e01c3dfb77e 100644
--- a/src/store/device/gitReview/store.test.ts
+++ b/src/store/device/gitReview/store.test.ts
@@ -615,6 +615,39 @@ describe('Review / PR tab replicas', () => {
expect(gitService.getLinkedPullRequest).not.toHaveBeenCalled();
expect(result.current.isLoading).toBe(false);
});
+
+ // Regression: SWR settles a request still in flight when its key goes null
+ // through the latest callbacks, which closed over null params, so a slow
+ // `gh` lookup that failed after the read was disabled threw
+ // "Cannot destructure property 'branch' of null" from `gitLinkedPRKey`.
+ it('settles a lookup that fails after the read is disabled', async () => {
+ let reject!: (error: unknown) => void;
+ vi.mocked(gitService.getLinkedPullRequest).mockImplementation(
+ () => new Promise((_resolve, rejectLookup) => (reject = rejectLookup)),
+ );
+ const linkedPR = useGitReviewStore.getState().slices.linkedPR;
+ // Earlier never-resolving reads stay pending on the shared slice.
+ const pendingBefore = linkedPR.debugPendingSyncRequests();
+ const unhandled = vi.fn();
+ process.on('unhandledRejection', unhandled);
+
+ try {
+ const { rerender } = renderHook(
+ ({ isGithub }) => useFetchGitLinkedPR('device-1', '/repo', 'feat/x', isGithub),
+ { initialProps: { isGithub: true }, wrapper },
+ );
+ await waitFor(() => expect(gitService.getLinkedPullRequest).toHaveBeenCalled());
+
+ rerender({ isGithub: false });
+ await act(async () => reject(new Error('gh pr list timed out')));
+ await new Promise((resolve) => setTimeout(resolve, 20));
+
+ expect(unhandled).not.toHaveBeenCalled();
+ expect(linkedPR.debugPendingSyncRequests()).toBe(pendingBefore);
+ } finally {
+ process.off('unhandledRejection', unhandled);
+ }
+ });
});
describe('linked PR key', () => {