Skip to content

Commit acaa63b

Browse files
perf(client): a reconnect snapshot keeps unchanged skills and providers identical
Co-Authored-By: Claude Opus 5.5 <[email protected]>
1 parent 2fbd431 commit acaa63b

2 files changed

Lines changed: 31 additions & 6 deletions

File tree

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

Lines changed: 23 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,8 @@
1+
import type { ServerConfig, ServerConfigStreamEvent } from "@t3tools/contracts";
2+
import * as Option from "effect/Option";
13
import { describe, expect, it } from "vite-plus/test";
24

3-
import { reuseUnchanged } from "./serverConfigProjection.ts";
5+
import { applyServerConfigProjection, reuseUnchanged } from "./serverConfigProjection.ts";
46

57
describe("reuseUnchanged", () => {
68
const provider = (checkedAt: string, skills: ReadonlyArray<string>) => ({
@@ -38,3 +40,23 @@ describe("reuseUnchanged", () => {
3840
expect(dropped).toEqual({ a: 1 });
3941
});
4042
});
43+
44+
describe("applyServerConfigProjection snapshot", () => {
45+
const snapshot = (checkedAt: string) =>
46+
({
47+
type: "snapshot",
48+
config: {
49+
environment: { capabilities: {} },
50+
providers: [{ instanceId: "claude", checkedAt, skills: [{ name: "review" }] }],
51+
},
52+
}) as unknown as ServerConfigStreamEvent;
53+
const providersOf = (projection: ReturnType<typeof applyServerConfigProjection>) =>
54+
(Option.getOrThrow(projection).config as ServerConfig).providers;
55+
56+
it("keeps unchanged skills when a reconnect re-sends the config", () => {
57+
const first = applyServerConfigProjection(Option.none(), snapshot("a"));
58+
const second = applyServerConfigProjection(first, snapshot("b"));
59+
expect(providersOf(second)[0]!.checkedAt).toBe("b");
60+
expect(providersOf(second)[0]!.skills).toBe(providersOf(first)[0]!.skills);
61+
});
62+
});

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

Lines changed: 8 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,7 @@ export function withoutEnvironmentThemes(config: ServerConfig): ServerConfig {
2424
* previous object. A provider status push re-sends every provider even when
2525
* only one field (often just `checkedAt`) changed, so this keeps unchanged
2626
* providers, models and skills identical and lets memoized UI skip them.
27+
* A reconnect snapshot re-sends the whole config the same way.
2728
*/
2829
export function reuseUnchanged<T>(previous: unknown, next: T): T {
2930
if (Object.is(previous, next)) return next;
@@ -78,12 +79,14 @@ export function applyServerConfigProjection(
7879
capabilities.usageLimitSources === true && Option.isSome(current)
7980
? current.value.config.usageLimitSources
8081
: undefined;
82+
const config: ServerConfig = {
83+
...event.config,
84+
...(carriedThemes === undefined ? {} : { environmentThemes: carriedThemes }),
85+
...(carriedSources === undefined ? {} : { usageLimitSources: carriedSources }),
86+
};
8187
return Option.some({
82-
config: {
83-
...event.config,
84-
...(carriedThemes === undefined ? {} : { environmentThemes: carriedThemes }),
85-
...(carriedSources === undefined ? {} : { usageLimitSources: carriedSources }),
86-
},
88+
// Every reconnect re-sends the whole config, usually unchanged apart from timestamps.
89+
config: Option.isSome(current) ? reuseUnchanged(current.value.config, config) : config,
8790
latestEvent: event,
8891
source: "live" as const,
8992
});

0 commit comments

Comments
 (0)