@devries-cameron20 / t3code Mirror · read-only / commits / 0c48f62705
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 23, 08:00 UTC

perf(client): provider status pushes keep unchanged providers identical (#20392)

Co-authored-by: Claude Opus 5.5 <noreply@anthropic.com>

Julius Marminge committed Oct 16, 2026 at 17:43 UTC 0c48f62705df3568d6dcb7abee9361c6ecaad855
4 files changed +87 -37
apps/web/src/components/ChatView.tsx
+2 -35
@@ -6055,46 +6055,13 @@ export default function ChatView(props: ChatViewProps) {
6055 isDesktop: isElectron,
6056 });
6057 const getShortcutContextStable = useStableCallback(getShortcutContext);
6058 - // Every provider status push carries a new skills array, even when nothing in
6059 - // it changed. Timeline markdown only reads names, so it keeps one identity
6060 - // until those change; otherwise each push re-renders every visible reply.
6061 - const nextTimelineSkills = activeProviderStatus
6058 + const timelineSkills = activeProviderStatus
6059 ? resolveProviderSkillsForCwd(activeProviderStatus, gitCwd)
6060 : EMPTY_PROVIDER_SKILLS;
6064 - const timelineSkillsKey = nextTimelineSkills
6065 - .map((skill) => `${skill.name}\u0000${skill.displayName ?? ""}`)
6066 - .join("\u0001");
6067 - const [timelineSkillsState, setTimelineSkillsState] = useState({
6068 - key: timelineSkillsKey,
6069 - skills: nextTimelineSkills,
6070 - });
6071 - if (timelineSkillsState.key !== timelineSkillsKey) {
6072 - setTimelineSkillsState({ key: timelineSkillsKey, skills: nextTimelineSkills });
6073 - }
6074 - const timelineSkills = timelineSkillsState.skills;
6075 - // Same for providers: timeline rows show their names, icons and models, and
6076 - // nothing else in a status push should re-render the conversation.
6077 - const nextTimelineProviders =
6061 + const timelineProviders =
6062 environmentById.get(
6063 displayedThreadRef?.environmentId ?? activeThread?.environmentId ?? environmentId,
6064 )?.serverConfig?.providers ?? EMPTY_PROVIDERS;
6081 - const timelineProvidersKey = JSON.stringify(
6082 - nextTimelineProviders.map((provider) => [
6083 - provider.instanceId,
6084 - provider.driver,
6085 - provider.displayName,
6086 - provider.iconUrl,
6087 - provider.models.map((model) => [model.slug, model.name, model.shortName]),
6088 - ]),
6089 - );
6090 - const [timelineProvidersState, setTimelineProvidersState] = useState({
6091 - key: timelineProvidersKey,
6092 - providers: nextTimelineProviders,
6093 - });
6094 - if (timelineProvidersState.key !== timelineProvidersKey) {
6095 - setTimelineProvidersState({ key: timelineProvidersKey, providers: nextTimelineProviders });
6096 - }
6097 - const timelineProviders = timelineProvidersState.providers;
6065 const threadFindControlsRef = useRef<ThreadFindControls | null>(null);
6066 const [isThreadFindActive, setIsThreadFindActive] = useState(false);
6067 const openThreadFind = () => threadFindControlsRef.current?.open();
packages/client-runtime/src/state/server.test.ts
+3 -1
@@ -870,7 +870,9 @@ describe("server state projection", () => {
870 ),
871 Stream.runHead,
872 );
873 - expect(Option.getOrThrow(Option.getOrThrow(projected)).config.providers).toBe(providers);
873 + expect(Option.getOrThrow(Option.getOrThrow(projected)).config.providers).toEqual(
874 + providers,
875 + );
876 }),
877 );
878
packages/client-runtime/src/state/serverConfigProjection.test.ts new
+40
@@ -0,0 +1,40 @@
1 +import { describe, expect, it } from "vite-plus/test";
2 +
3 +import { reuseUnchanged } from "./serverConfigProjection.ts";
4 +
5 +describe("reuseUnchanged", () => {
6 + const provider = (checkedAt: string, skills: ReadonlyArray<string>) => ({
7 + instanceId: "claude",
8 + checkedAt,
9 + models: [{ slug: "opus", name: "Opus" }],
10 + skills: skills.map((name) => ({ name })),
11 + });
12 +
13 + it("returns the previous value when nothing changed", () => {
14 + const previous = [provider("a", ["x"])];
15 + expect(reuseUnchanged(previous, [provider("a", ["x"])])).toBe(previous);
16 + });
17 +
18 + it("keeps unchanged parts when one field changes", () => {
19 + const previous = [provider("a", ["x"]), { ...provider("a", ["y"]), instanceId: "codex" }];
20 + const next = reuseUnchanged(previous, [
21 + provider("b", ["x"]),
22 + { ...provider("a", ["y"]), instanceId: "codex" },
23 + ]);
24 + expect(next).not.toBe(previous);
25 + expect(next[0]).not.toBe(previous[0]);
26 + expect(next[0]!.checkedAt).toBe("b");
27 + expect(next[0]!.models).toBe(previous[0]!.models);
28 + expect(next[0]!.skills).toBe(previous[0]!.skills);
29 + expect(next[1]).toBe(previous[1]);
30 + });
31 +
32 + it("takes the new value when keys or lengths change", () => {
33 + const previous = [provider("a", ["x"])];
34 + const next = reuseUnchanged(previous, [provider("a", ["x", "z"])]);
35 + expect(next[0]!.skills).toHaveLength(2);
36 + expect(next[0]!.models).toBe(previous[0]!.models);
37 + const dropped = reuseUnchanged({ a: 1, b: 2 }, { a: 1 });
38 + expect(dropped).toEqual({ a: 1 });
39 + });
40 +});
packages/client-runtime/src/state/serverConfigProjection.ts
+42 -1
@@ -19,6 +19,47 @@ export function withoutEnvironmentThemes(config: ServerConfig): ServerConfig {
19 return rest;
20 }
21
22 +/**
23 + * Returns `next` with every part deep-equal to `previous` replaced by the
24 + * previous object. A provider status push re-sends every provider even when
25 + * only one field (often just `checkedAt`) changed, so this keeps unchanged
26 + * providers, models and skills identical and lets memoized UI skip them.
27 + */
28 +export function reuseUnchanged<T>(previous: unknown, next: T): T {
29 + if (Object.is(previous, next)) return next;
30 + if (
31 + typeof previous !== "object" ||
32 + typeof next !== "object" ||
33 + previous === null ||
34 + next === null ||
35 + Array.isArray(previous) !== Array.isArray(next)
36 + ) {
37 + return next;
38 + }
39 + if (Array.isArray(next)) {
40 + const before = previous as ReadonlyArray<unknown>;
41 + let same = before.length === next.length;
42 + const merged = next.map((item, index) => {
43 + const reused = reuseUnchanged(before[index], item);
44 + if (reused !== before[index]) same = false;
45 + return reused;
46 + });
47 + return (same ? previous : merged) as T;
48 + }
49 + if (Object.getPrototypeOf(next) !== Object.prototype) return next;
50 + const before = previous as Record<string, unknown>;
51 + const after = next as Record<string, unknown>;
52 + const keys = Object.keys(after);
53 + let same = keys.length === Object.keys(before).length;
54 + const merged: Record<string, unknown> = {};
55 + for (const key of keys) {
56 + const reused = reuseUnchanged(before[key], after[key]);
57 + if (reused !== before[key] || !(key in before)) same = false;
58 + merged[key] = reused;
59 + }
60 + return (same ? previous : merged) as T;
61 +}
62 +
63 export function applyServerConfigProjection(
64 current: Option.Option<ServerConfigProjection>,
65 event: ServerConfigStreamEvent,
@@ -61,7 +102,7 @@ export function applyServerConfigProjection(
102 return Option.map(current, (projection) => ({
103 config: {
104 ...projection.config,
64 - providers: event.payload.providers,
105 + providers: reuseUnchanged(projection.config.providers, event.payload.providers),
106 },
107 latestEvent: event,
108 source: "live",