The best way to control Claude Code, Codex and more from any computer or phone
perf(client): repeated server settings keep the same settings object (#27818)
Co-authored-by: Claude Opus 5.5 <noreply@anthropic.com>
MarcoDotIO committed
Nov 1, 2026 at 16:49 UTC
8a18bbf281490ae462cdbfed2ba6e1ffeb9121f7
2 files changed
+40
-9
packages/client-runtime/src/state/serverConfigProjection.test.ts
+26
-1
@@ -1,9 +1,18 @@
1
-import type { ServerConfig, ServerConfigStreamEvent } from "@t3tools/contracts";
1
+import {
2
+ DEFAULT_SERVER_SETTINGS,
3
+ ServerSettings,
4
+ type ServerConfig,
5
+ type ServerConfigStreamEvent,
6
+} from "@t3tools/contracts";
7
import * as Option from "effect/Option";
8
+import * as Schema from "effect/Schema";
9
import { describe, expect, it } from "vite-plus/test";
10
11
import { applyServerConfigProjection, reuseUnchanged } from "./serverConfigProjection.ts";
12
13
+const encodeSettings = Schema.encodeSync(ServerSettings);
14
+const decodeSettings = Schema.decodeSync(ServerSettings);
15
+
16
describe("reuseUnchanged", () => {
17
const provider = (checkedAt: string, skills: ReadonlyArray<string>) => ({
18
instanceId: "claude",
@@ -53,4 +62,20 @@ describe("applyServerConfigProjection settingsUpdated", () => {
62
expect(nextSettings.providerInstances.codex).toBe(settings.providerInstances.codex);
63
expect(nextSettings.providerInstances.claude.config.launchArgs).toBe("--verbose");
64
});
65
+
66
+ it("keeps the settings object when an update repeats the current settings", () => {
67
+ const wire = encodeSettings(DEFAULT_SERVER_SETTINGS);
68
+ const decode = () => decodeSettings(structuredClone(wire));
69
+ const settings = decode();
70
+ const current = Option.some({
71
+ config: { settings } as unknown as ServerConfig,
72
+ latestEvent: {} as ServerConfigStreamEvent,
73
+ source: "live" as const,
74
+ });
75
+ const next = applyServerConfigProjection(current, {
76
+ type: "settingsUpdated",
77
+ payload: { settings: decode() },
78
+ } as ServerConfigStreamEvent);
79
+ expect(Option.getOrThrow(next).config).toBe(Option.getOrThrow(current).config);
80
+ });
81
});
packages/client-runtime/src/state/serverConfigProjection.ts
+14
-8
@@ -1,4 +1,5 @@
1
import type { ServerConfig, ServerConfigStreamEvent } from "@t3tools/contracts";
2
+import * as Equal from "effect/Equal";
3
import * as Option from "effect/Option";
4
5
export interface ServerConfigProjection {
@@ -44,6 +45,8 @@ export function reuseUnchanged<T>(previous: unknown, next: T): T {
45
});
46
return (same ? previous : merged) as T;
47
}
48
+ // Decoded settings carry Durations, which are fresh instances on every push.
49
+ if (Equal.isEqual(next)) return (Equal.equals(previous, next) ? previous : next) as T;
50
if (Object.getPrototypeOf(next) !== Object.prototype) return next;
51
const before = previous as Record<string, unknown>;
52
const after = next as Record<string, unknown>;
@@ -104,14 +107,17 @@ export function applyServerConfigProjection(
107
source: "live",
108
}));
109
case "settingsUpdated":
107
- return Option.map(current, (projection) => ({
108
- config: {
109
- ...projection.config,
110
- settings: reuseUnchanged(projection.config.settings, event.payload.settings),
111
- },
112
- latestEvent: event,
113
- source: "live",
114
- }));
110
+ return Option.map(current, (projection) => {
111
+ const settings = reuseUnchanged(projection.config.settings, event.payload.settings);
112
+ return {
113
+ config:
114
+ settings === projection.config.settings
115
+ ? projection.config
116
+ : { ...projection.config, settings },
117
+ latestEvent: event,
118
+ source: "live",
119
+ };
120
+ });
121
case "environmentThemesUpdated":
122
return Option.map(current, (projection) => ({
123
config: {