TypeScript
perf(client): a repository identity refresh keeps unchanged projects identical (#20730)
Julius Marminge3cb13308eb27
diff --git a/packages/client-runtime/src/state/shellReducer.test.ts b/packages/client-runtime/src/state/shellReducer.test.tsindex 42a32aca702..6f09385da2b 100644--- a/packages/client-runtime/src/state/shellReducer.test.ts+++ b/packages/client-runtime/src/state/shellReducer.test.ts@@ -226,6 +226,22 @@ describe("applyShellStreamEvent", () => {expect(afterEnrichment.threads[0]?.title).toBe("Server thread");});+ it("keeps the project object when an enrichment re-resolves an unchanged identity", () => {+ const project = { ...v2Project, repositoryIdentity };+ const previous = { ...v2ShellSnapshot, snapshotSequence: 5, projects: [project] };+ const next = mergeShellSnapshotProjects(+ previous,+ {+ ...v2ShellSnapshot,+ snapshotSequence: 5,+ projects: [{ ...v2Project, repositoryIdentity: { ...repositoryIdentity } }],+ },+ { resolvedRepositoryIdentityRoots: [v2Project.workspaceRoot] },+ );++ expect(next.projects[0]).toBe(project);+ });+it("takes identity from a lower-sequence enrichment without reverting live thread state", () => {const previous = {...v2ShellSnapshot,diff --git a/packages/client-runtime/src/state/shellReducer.ts b/packages/client-runtime/src/state/shellReducer.tsindex 2cd2468d039..b37bc38a1af 100644--- a/packages/client-runtime/src/state/shellReducer.ts+++ b/packages/client-runtime/src/state/shellReducer.ts@@ -1,5 +1,6 @@import {OrchestrationV2ThreadShell,+ RepositoryIdentity,ThreadPullRequestLink,type OrchestrationProjectShell,type OrchestrationV2ShellSnapshot,@@ -9,6 +10,9 @@ import * as Schema from "effect/Schema";const sameThreadShell = Schema.toEquivalence(OrchestrationV2ThreadShell);const sameLinks = Schema.toEquivalence(Schema.UndefinedOr(Schema.Array(ThreadPullRequestLink)));+const sameRepositoryIdentity = Schema.toEquivalence(+ Schema.UndefinedOr(Schema.NullOr(RepositoryIdentity)),+);export function sameThreadPullRequests(left: OrchestrationV2ThreadShell["pullRequests"],@@ -96,6 +100,11 @@ export function mergeShellSnapshotProjects(return project;}if (resolvedRootSet?.has(project.workspaceRoot) === true) {+ // Refreshes re-resolve every root; an unchanged identity keeps the project's identity+ // so every subscriber (each pull request row, the sidebar) skips re-rendering.+ if (sameRepositoryIdentity(project.repositoryIdentity, candidate.repositoryIdentity)) {+ return project;+ }return { ...project, repositoryIdentity: candidate.repositoryIdentity };}if (project.repositoryIdentity == null && candidate.repositoryIdentity != null) {