@devries-cameron20 / t3code Mirror · read-only / commits / bd907328f3
Fork 0

The best way to control Claude Code, Codex and more from any computer or phone

Mirrored from https://github.com/Camo67/t3code.git

Synced Nov 22, 08:15 UTC

fix(client): a resume no longer re-renders every home row five times (#27404)

Co-authored-by: Claude Opus 5.5 <noreply@anthropic.com> Co-authored-by: maria-rcks <254055478+maria-rcks@users.noreply.github.com>

ahalekelly committed Nov 1, 2026 at 13:44 UTC bd907328f38a22615b7b019b73f5f30a3d4948f2
6 files changed +33 -20
apps/mobile/src/state/session.test.ts
+3 -2
@@ -13,9 +13,10 @@ vi.mock("react", () => ({ useMemo: <A>(factory: () => A) => factory() }));
13 vi.mock("@effect/atom-react", async () => {
14 const { appAtomRegistry } = await import("./atom-registry");
15 return {
16 - useAtomValue: <A>(atom: Atom.Atom<A>) => {
16 + useAtomValue: <A, B>(atom: Atom.Atom<A>, select?: (value: A) => B) => {
17 harness.lastAtom = atom;
18 - return appAtomRegistry.get(atom);
18 + const value = appAtomRegistry.get(atom);
19 + return select === undefined ? value : select(value);
20 },
21 };
22 });
apps/mobile/src/state/session.ts
+3 -2
@@ -29,12 +29,13 @@ export function useEnvironmentScope(
29 environmentId: EnvironmentId | null,
30 scope: AuthEnvironmentScope,
31 ): boolean {
32 - const result = useAtomValue(
32 + // Select the grant: every revalidation emits a new result, and most consumers are list rows.
33 + return useAtomValue(
34 environmentId === null
35 ? EMPTY_SESSION_STATE_ATOM
36 : environmentSession.sessionStateAtom(environmentId),
37 + (result) => sessionHasScope(result, scope),
38 );
37 - return sessionHasScope(result, scope);
39 }
40
41 export function useEnvironmentsWithScope(
apps/web/src/components/ServerUpdateAction.tsx
+1 -1
@@ -272,7 +272,7 @@ export function ServerUpdateAction({
272 const isDesktopAppUpdate = selfUpdate === "desktop-managed";
273 const serverVersion = useServerConfigs().get(environmentId)?.environment.serverVersion;
274 const sessionStateAtom = environmentSession.sessionStateAtom(environmentId);
275 - const canUpdate = canUpdateServer(useAtomValue(sessionStateAtom));
275 + const canUpdate = useAtomValue(sessionStateAtom, canUpdateServer);
276 const updatesDenial = managedUpdatesDenial(useManagedPolicy(environmentId));
277 const update = useServerUpdate();
278 const { copyToClipboard } = useCopyToClipboard<{ command: string }>({
apps/web/src/state/session.ts
+3 -2
@@ -25,12 +25,13 @@ export function useEnvironmentScope(
25 environmentId: EnvironmentId | null,
26 scope: AuthEnvironmentScope,
27 ): boolean {
28 - const result = useAtomValue(
28 + // Select the grant: every revalidation emits a new result, and most consumers are list rows.
29 + return useAtomValue(
30 environmentId === null
31 ? EMPTY_SESSION_STATE_ATOM
32 : environmentSession.sessionStateAtom(environmentId),
33 + (result) => sessionHasScope(result, scope),
34 );
33 - return sessionHasScope(result, scope);
35 }
36
37 export function sessionHasScope(
packages/client-runtime/src/state/shellReducer.test.ts
+11 -2
@@ -87,22 +87,31 @@ describe("applyShellStreamEvent", () => {
87 });
88
89 it("authoritative lower-sequence reset replaces client-ahead structural state", () => {
90 + const unchanged = { ...v2Project, id: ProjectId.make("project-unchanged"), repositoryIdentity };
91 const previous = {
92 ...v2ShellSnapshot,
93 snapshotSequence: 9,
93 - projects: [{ ...v2Project, title: "Client ahead", repositoryIdentity }],
94 + projects: [{ ...v2Project, title: "Client ahead", repositoryIdentity }, unchanged],
95 threads: [{ ...v2ThreadShell, title: "Local-only thread" }],
96 };
97 const next = mergeShellSnapshotProjects(previous, {
98 ...v2ShellSnapshot,
99 snapshotSequence: 3,
99 - projects: [{ ...v2Project, title: "Server reset", repositoryIdentity: null }],
100 + projects: [
101 + { ...v2Project, title: "Server reset", repositoryIdentity: null },
102 + { ...unchanged, scripts: [...unchanged.scripts] },
103 + ],
104 threads: [{ ...v2ThreadShell, title: "Server thread" }],
105 });
106
107 expect(next.snapshotSequence).toBe(3);
108 expect(next.projects[0]?.title).toBe("Server reset");
109 expect(next.projects[0]?.repositoryIdentity).toEqual(repositoryIdentity);
110 + expect(next.projects[1]).toBe(unchanged);
111 + expect(
112 + mergeShellSnapshotProjects(next, { ...v2ShellSnapshot, projects: [...next.projects] })
113 + .projects,
114 + ).toBe(next.projects);
115 expect(next.threads[0]?.title).toBe("Server thread");
116 });
117
packages/client-runtime/src/state/shellReducer.ts
+12 -11
@@ -1,14 +1,15 @@
1 import {
2 + OrchestrationProjectShell,
3 OrchestrationV2ThreadShell,
4 RepositoryIdentity,
5 ThreadPullRequestLink,
5 - type OrchestrationProjectShell,
6 type OrchestrationV2ShellSnapshot,
7 type OrchestrationV2ShellStreamItem,
8 } from "@t3tools/contracts";
9 import * as Schema from "effect/Schema";
10
11 const sameThreadShell = Schema.toEquivalence(OrchestrationV2ThreadShell);
12 +const sameProjectShell = Schema.toEquivalence(OrchestrationProjectShell);
13 const sameLinks = Schema.toEquivalence(Schema.UndefinedOr(Schema.Array(ThreadPullRequestLink)));
14 const sameRepositoryIdentity = Schema.toEquivalence(
15 Schema.UndefinedOr(Schema.NullOr(RepositoryIdentity)),
@@ -116,16 +117,16 @@ export function mergeShellSnapshotProjects(
117 }
118
119 const previousById = new Map(previous.projects.map((project) => [project.id, project] as const));
119 - return {
120 - ...next,
121 - projects: next.projects.map((project) => {
122 - const prior = previousById.get(project.id);
123 - if (resolvedRootSet?.has(project.workspaceRoot) === true) {
124 - return project;
125 - }
126 - return retainRepositoryIdentity(prior, project);
127 - }),
128 - };
120 + // Project atoms and shell persistence compare by reference, so unchanged projects keep their objects.
121 + const projects = next.projects.map((project) => {
122 + const prior = previousById.get(project.id);
123 + const merged = retainRepositoryIdentity(prior, project);
124 + return prior !== undefined && sameProjectShell(prior, merged) ? prior : merged;
125 + });
126 + const unchanged =
127 + projects.length === previous.projects.length &&
128 + projects.every((project, index) => project === previous.projects[index]);
129 + return { ...next, projects: unchanged ? previous.projects : projects };
130 }
131
132 export function applyShellStreamEvent(