Skip to content

Commit 4e7d564

Browse files
refactor(web): settings panels derive drafts and load data from atoms
Settings panels stop copying props into editable state and stop running loads and follow-up steps from effects. Codex setup awaits its own install and sign-in operations instead of watching shared phases. Effect categories removed: - props mirrored into editable drafts (environment rows, command arguments, accent color, icon picker) derived during render or held in bodies keyed per open - latest-value ref mirrors replaced by bodies keyed by environment - data loading moved to atoms (registry icons, CLI state, cloud link poll, licenses, diff font preview, OTLP checks, SnapShot state) - event logic in effects moved to handlers (color commits, theme search and import, search reveals, Codex install then sign-in) - terminal previews, shadow roots and scroll-into-view moved to ref callbacks - timers moved to shared clocks (retry countdown, relative times) - search shortcut moved to a dispatcher scope; effect-driven navigation replaced by a rendered redirect Bugs fixed: - Updating Codex could sign in against the old binary. - A sign-in flow started from another client or tab opened a browser page here. - A picked accent color was lost when the row unmounted with the popover open. - The storage cleanup "Last run" label never advanced. - A font typed less than 400ms before its row unmounted was dropped. Kept effects: - Codex setup handoff import, auto-start and unmount abort: server phases or component-owned continuations with no local handler. - Desktop auth-callback cancel listener: lifetime is component plus URL. - Terminal preview output, font and theme pushes: imperative widget. - Theme editor preview, inspector and document listeners: external document state. - Font picker open-after-mount: Base UI needs one closed commit. - SnapShot recorder release: OS shortcut suppression on unmount. Co-Authored-By: Claude Opus 5.5 <[email protected]>
1 parent 140aab1 commit 4e7d564

51 files changed

Lines changed: 2459 additions & 1503 deletions

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

‎apps/web/src/cloud/primaryCloudLinkState.ts‎

Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -56,6 +56,29 @@ function refreshPrimaryCloudLinkState(target: CloudLinkTarget | null): void {
5656
}
5757
}
5858

59+
const NO_PRIMARY_CLOUD_LINK_POLL_ATOM = Atom.make<void>(undefined).pipe(
60+
Atom.withLabel("primary-cloud-link:poll:none"),
61+
);
62+
63+
const primaryCloudLinkPollAtomFamily = Atom.family((key: string) =>
64+
Atom.make((get) => {
65+
const target = JSON.parse(key) as CloudLinkTarget;
66+
const interval = setInterval(() => refreshPrimaryCloudLinkState(target), 30_000);
67+
get.addFinalizer(() => clearInterval(interval));
68+
}).pipe(Atom.withLabel(`primary-cloud-link:poll:${key}`)),
69+
);
70+
71+
/**
72+
* Re-reads the link state every 30 s while mounted. The server rechecks tunnel
73+
* reachability on its own readiness poll, and a failed read must not stop
74+
* later ones.
75+
*/
76+
export function primaryCloudLinkPollAtom(target: CloudLinkTarget | null): Atom.Atom<void> {
77+
return target
78+
? primaryCloudLinkPollAtomFamily(targetKey(target))
79+
: NO_PRIMARY_CLOUD_LINK_POLL_ATOM;
80+
}
81+
5982
export function readCachedPrimaryCloudLinkState(target: CloudLinkTarget) {
6083
if (!readEnvironmentScope(EnvironmentId.make(target.environmentId), AuthRelayReadScope))
6184
return null;

‎apps/web/src/components/settings/AcpRegistryIcon.tsx‎

Lines changed: 43 additions & 40 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,8 @@
1-
import { useEffect, useId, useState } from "react";
1+
import { useAtomValue } from "@effect/atom-react";
2+
import * as Effect from "effect/Effect";
3+
import * as Option from "effect/Option";
4+
import { AsyncResult, Atom } from "effect/reactivity";
5+
import { useId, useState } from "react";
26
import {
37
resolveOfficialAcpRegistryIconUrl,
48
officialAcpRegistryIconUrlForAgentId,
@@ -66,6 +70,33 @@ export function loadCachedAcpRegistryIcon(iconUrl: string): Promise<Blob> {
6670
return load;
6771
}
6872

73+
// Falls back to the raw allowlisted CDN URL when the validating fetch fails: the
74+
// CDN serves no CORS headers, so the fetch is often blocked cross-origin while
75+
// native <img> loading still works. The object URL is shared per agent and
76+
// revoked when the last icon unmounts.
77+
const acpRegistryIconSourceAtom = Atom.family((iconUrl: string) =>
78+
Atom.make((get) => {
79+
let disposed = false;
80+
let objectUrl: string | null = null;
81+
get.addFinalizer(() => {
82+
disposed = true;
83+
if (objectUrl !== null) URL.revokeObjectURL(objectUrl);
84+
});
85+
return Effect.promise(() =>
86+
loadCachedAcpRegistryIcon(iconUrl).then(
87+
(blob) => {
88+
if (disposed) return iconUrl;
89+
objectUrl = URL.createObjectURL(blob);
90+
return objectUrl;
91+
},
92+
() => iconUrl,
93+
),
94+
);
95+
}).pipe(Atom.withLabel(`acp-registry-icon:${iconUrl}`)),
96+
);
97+
98+
const NO_ICON_SOURCE_ATOM = Atom.make(AsyncResult.initial<string>());
99+
69100
export function AcpRegistryAgentIcon({
70101
icon,
71102
className,
@@ -77,37 +108,18 @@ export function AcpRegistryAgentIcon({
77108
}) {
78109
const colorFilterId = useId();
79110
const iconUrl = resolveOfficialAcpRegistryIconUrl(icon);
111+
// Render only after the load pipeline resolves, so the fallback icon does
112+
// not flash a broken image.
113+
const source = Option.getOrNull(
114+
AsyncResult.value(
115+
useAtomValue(iconUrl === null ? NO_ICON_SOURCE_ATOM : acpRegistryIconSourceAtom(iconUrl)),
116+
),
117+
);
80118
const [image, setImage] = useState<{
81-
readonly iconUrl: string;
82119
readonly source: string;
83-
readonly status: "loading" | "loaded" | "failed";
120+
readonly status: "loaded" | "failed";
84121
} | null>(null);
85-
const currentImage = image?.iconUrl === iconUrl ? image : null;
86-
// The CDN lacks CORS headers; native img loading can succeed after a validating fetch fails.
87-
const source = currentImage?.source ?? null;
88-
const status = currentImage?.status ?? "loading";
89-
90-
useEffect(() => {
91-
if (iconUrl === null) return;
92-
let active = true;
93-
let objectUrl: string | null = null;
94-
void loadCachedAcpRegistryIcon(iconUrl)
95-
.then((blob) => {
96-
if (!active) return;
97-
objectUrl = URL.createObjectURL(blob);
98-
setImage({ iconUrl, source: objectUrl, status: "loading" });
99-
})
100-
.catch(() => {
101-
if (!active) return;
102-
setImage((current) =>
103-
current?.iconUrl === iconUrl ? current : { iconUrl, source: iconUrl, status: "loading" },
104-
);
105-
});
106-
return () => {
107-
active = false;
108-
if (objectUrl !== null) URL.revokeObjectURL(objectUrl);
109-
};
110-
}, [iconUrl]);
122+
const status = source !== null && image?.source === source ? image.status : "loading";
111123

112124
return (
113125
<span
@@ -144,17 +156,8 @@ export function AcpRegistryAgentIcon({
144156
decoding="async"
145157
referrerPolicy="no-referrer"
146158
src={source}
147-
onError={() => {
148-
if (iconUrl === null) return;
149-
setImage((current) =>
150-
current?.iconUrl === iconUrl && current.source !== source
151-
? current
152-
: { iconUrl, source, status: "failed" },
153-
);
154-
}}
155-
onLoad={() => {
156-
if (iconUrl !== null) setImage({ iconUrl, source, status: "loaded" });
157-
}}
159+
onError={() => setImage({ source, status: "failed" })}
160+
onLoad={() => setImage({ source, status: "loaded" })}
158161
/>
159162
) : null}
160163
</span>

‎apps/web/src/components/settings/AcpRegistrySearchStep.browser.test.tsx‎

Lines changed: 11 additions & 34 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@ import { EnvironmentId, ProviderDriverKind, type AcpRegistrySearchAgent } from "
22
import { expect, it, vi } from "vite-plus/test";
33
import { page } from "vite-plus/test/browser";
44

5-
import { act, render } from "../../../test/render";
5+
import { render } from "../../../test/render";
66

77
const state = vi.hoisted(() => ({
88
result: null as { readonly agents: ReadonlyArray<AcpRegistrySearchAgent> } | null,
@@ -46,7 +46,7 @@ vi.mock(import("../../state/use-atom-command"), async (original) => ({
4646
useAtomCommand: (() => state.prepare) as never,
4747
}));
4848

49-
import { AcpRegistrySearchStep } from "./AcpRegistrySearchStep";
49+
import { AcpRegistrySearchStep, useAcpRegistrySearch } from "./AcpRegistrySearchStep";
5050

5151
const environmentId = EnvironmentId.make("remote-device");
5252
const gemini: AcpRegistrySearchAgent = {
@@ -63,15 +63,20 @@ const gemini: AcpRegistrySearchAgent = {
6363
integrity: "registry",
6464
};
6565

66-
function step(options?: {
66+
function Step({
67+
configured = false,
68+
onPrepared = vi.fn(),
69+
}: {
6770
readonly configured?: boolean;
6871
readonly onPrepared?: (agent: AcpRegistrySearchAgent) => void;
6972
}) {
73+
const registry = useAcpRegistrySearch(environmentId, true);
7074
return (
7175
<AcpRegistrySearchStep
7276
environmentId={environmentId}
77+
registry={registry}
7378
providerInstances={
74-
options?.configured
79+
configured
7580
? {
7681
acpRegistry_gemini: {
7782
driver: ProviderDriverKind.make("acpRegistry"),
@@ -80,20 +85,12 @@ function step(options?: {
8085
}
8186
: {}
8287
}
83-
onPrepared={options?.onPrepared ?? vi.fn()}
88+
onPrepared={onPrepared}
8489
onManualConfiguration={vi.fn()}
8590
/>
8691
);
8792
}
8893

89-
function deferred<T>() {
90-
let resolve!: (value: T) => void;
91-
const promise = new Promise<T>((done) => {
92-
resolve = done;
93-
});
94-
return { promise, resolve };
95-
}
96-
9794
function setup() {
9895
state.canManage = true;
9996
state.result = null;
@@ -111,31 +108,11 @@ it("rechecks the grant before preparing an agent", async () => {
111108
setup();
112109
state.result = { agents: [gemini] };
113110
const onPrepared = vi.fn();
114-
await using _screen = await render(step({ onPrepared }));
111+
await using _screen = await render(<Step onPrepared={onPrepared} />);
115112
state.canManage = false;
116113

117114
await page.getByRole("button", { name: "Add Gemini CLI" }).click();
118115

119116
expect(state.prepare).not.toHaveBeenCalled();
120117
expect(onPrepared).not.toHaveBeenCalled();
121118
});
122-
123-
it("ignores prepare completion after unmount", async () => {
124-
setup();
125-
const pending = deferred<unknown>();
126-
state.prepare.mockReturnValueOnce(pending.promise);
127-
state.result = { agents: [gemini] };
128-
const onPrepared = vi.fn();
129-
await using screen = await render(step({ onPrepared }));
130-
131-
await page.getByRole("button", { name: "Add Gemini CLI" }).click();
132-
await screen.unmount();
133-
await act(async () =>
134-
pending.resolve({
135-
_tag: "Success",
136-
value: { agentId: "gemini", version: "1.2.3", distribution: "npx", prepared: true },
137-
}),
138-
);
139-
140-
expect(onPrepared).not.toHaveBeenCalled();
141-
});

0 commit comments

Comments
 (0)