Skip to content

Commit 3cb1330

Browse files
perf(client): a repository identity refresh keeps unchanged projects identical (pingdotgg#20730)
Co-authored-by: Claude Opus 5.5 <[email protected]>
1 parent 23163fd commit 3cb1330

2 files changed

Lines changed: 25 additions & 0 deletions

File tree

‎packages/client-runtime/src/state/shellReducer.test.ts‎

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -226,6 +226,22 @@ describe("applyShellStreamEvent", () => {
226226
expect(afterEnrichment.threads[0]?.title).toBe("Server thread");
227227
});
228228

229+
it("keeps the project object when an enrichment re-resolves an unchanged identity", () => {
230+
const project = { ...v2Project, repositoryIdentity };
231+
const previous = { ...v2ShellSnapshot, snapshotSequence: 5, projects: [project] };
232+
const next = mergeShellSnapshotProjects(
233+
previous,
234+
{
235+
...v2ShellSnapshot,
236+
snapshotSequence: 5,
237+
projects: [{ ...v2Project, repositoryIdentity: { ...repositoryIdentity } }],
238+
},
239+
{ resolvedRepositoryIdentityRoots: [v2Project.workspaceRoot] },
240+
);
241+
242+
expect(next.projects[0]).toBe(project);
243+
});
244+
229245
it("takes identity from a lower-sequence enrichment without reverting live thread state", () => {
230246
const previous = {
231247
...v2ShellSnapshot,

‎packages/client-runtime/src/state/shellReducer.ts‎

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
import {
22
OrchestrationV2ThreadShell,
3+
RepositoryIdentity,
34
ThreadPullRequestLink,
45
type OrchestrationProjectShell,
56
type OrchestrationV2ShellSnapshot,
@@ -9,6 +10,9 @@ import * as Schema from "effect/Schema";
910

1011
const sameThreadShell = Schema.toEquivalence(OrchestrationV2ThreadShell);
1112
const sameLinks = Schema.toEquivalence(Schema.UndefinedOr(Schema.Array(ThreadPullRequestLink)));
13+
const sameRepositoryIdentity = Schema.toEquivalence(
14+
Schema.UndefinedOr(Schema.NullOr(RepositoryIdentity)),
15+
);
1216

1317
export function sameThreadPullRequests(
1418
left: OrchestrationV2ThreadShell["pullRequests"],
@@ -96,6 +100,11 @@ export function mergeShellSnapshotProjects(
96100
return project;
97101
}
98102
if (resolvedRootSet?.has(project.workspaceRoot) === true) {
103+
// Refreshes re-resolve every root; an unchanged identity keeps the project's identity
104+
// so every subscriber (each pull request row, the sidebar) skips re-rendering.
105+
if (sameRepositoryIdentity(project.repositoryIdentity, candidate.repositoryIdentity)) {
106+
return project;
107+
}
99108
return { ...project, repositoryIdentity: candidate.repositoryIdentity };
100109
}
101110
if (project.repositoryIdentity == null && candidate.repositoryIdentity != null) {

0 commit comments

Comments
 (0)