Skip to content

Commit 90c4aa2

Browse files
committed
fix(gui): stop the browser-open toggle from issuing its own settings fetch
1 parent c6c98e9 commit 90c4aa2

4 files changed

Lines changed: 17 additions & 31 deletions

File tree

‎gui/src/components/AddProviderModal.tsx‎

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -275,7 +275,6 @@ export default function AddProviderModal({
275275
preset.auth === "oauth" && form.authMode === "oauth" ? (
276276
<AddProviderOAuthPane
277277
preset={preset}
278-
apiBase={apiBase}
279278
oauthSupported={oauthSupported}
280279
oauthBusy={oauthBusy}
281280
oauthMsg={oauthMsg}

‎gui/src/components/add-provider-oauth-pane.tsx‎

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,6 @@ import type { CatalogPreset } from "./provider-catalog/provider-presets";
66

77
export function AddProviderOAuthPane({
88
preset,
9-
apiBase,
109
oauthSupported,
1110
oauthBusy,
1211
oauthMsg,
@@ -25,7 +24,6 @@ export function AddProviderOAuthPane({
2524
onBack,
2625
}: {
2726
preset: CatalogPreset;
28-
apiBase: string;
2927
oauthSupported: string[];
3028
oauthBusy: boolean;
3129
oauthMsg: string;
@@ -54,7 +52,7 @@ export function AddProviderOAuthPane({
5452
style={{ width: "100%", padding: "12px 16px" }}>
5553
<IconLock />{oauthBusy ? t("modal.waitingBrowser") : t("modal.logInWith", { label: preset.label })}
5654
</button>
57-
{!oauthBusy && <OpenBrowserPrefToggle apiBase={apiBase} />}
55+
{!oauthBusy && <OpenBrowserPrefToggle />}
5856
</>
5957
) : (
6058
<div className="text-control" style={{ color: "var(--amber)", background: "var(--amber-soft)", border: "1px solid var(--amber)", borderRadius: "var(--radius-sm)", padding: "10px 12px" }}>

‎gui/src/components/open-browser-pref-toggle.tsx‎

Lines changed: 15 additions & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,5 @@
11
import { useState } from "react";
22
import { useT } from "../i18n/shared";
3-
import { useKeyedClientResource } from "../client-resource";
43
import { readOpenBrowserPref, writeOpenBrowserPref } from "../oauth-open-browser-pref";
54

65
/**
@@ -15,32 +14,22 @@ import { readOpenBrowserPref, writeOpenBrowserPref } from "../oauth-open-browser
1514
* nothing is spawned on the proxy's machine, so the operator opens the link
1615
* wherever they actually want to be signed in.
1716
*/
18-
export function OpenBrowserPrefToggle({ apiBase }: { apiBase?: string }) {
17+
/**
18+
* `serverDefault` is the persisted `oauthOpenBrowser` when the caller already
19+
* has it. This component deliberately does **not** fetch it: an auth panel that
20+
* quietly issued its own `/api/settings` request would make every surrounding
21+
* surface's request accounting wrong, and it did — it broke the account-import
22+
* tests, which assert exactly how many calls a selection makes.
23+
*
24+
* Not fetching costs nothing that matters. With no local preference the request
25+
* omits `openBrowser` entirely, so the persisted setting still governs what the
26+
* proxy actually does; only the initial checkbox rendering falls back to the
27+
* historical auto-open.
28+
*/
29+
export function OpenBrowserPrefToggle({ serverDefault = true }: { serverDefault?: boolean }) {
1930
const t = useT();
20-
// A local preference wins outright; otherwise the box mirrors the persisted
21-
// setting, so the checkbox and the config file never disagree on screen.
22-
const localPref = readOpenBrowserPref();
23-
const [choice, setChoice] = useState<boolean | undefined>(localPref);
24-
25-
// The server default is a fetched RESOURCE, not component state, so it does
26-
// not need a post-await setState — which is both the react-doctor rule and
27-
// the honest model: this component owns the operator's choice, not the
28-
// server's setting.
29-
const serverPref = useKeyedClientResource(
30-
`oauth-open-browser:${apiBase ?? ""}`,
31-
[apiBase],
32-
async (signal) => {
33-
if (!apiBase) return true;
34-
const res = await fetch(`${apiBase}/api/settings`, { signal });
35-
if (!res.ok) return true;
36-
const data = await res.json() as { oauthOpenBrowser?: boolean };
37-
return typeof data.oauthOpenBrowser === "boolean" ? data.oauthOpenBrowser : true;
38-
},
39-
);
40-
41-
// Until this operator chooses, follow the server; a failed read leaves the
42-
// historical auto-open on screen.
43-
const open = choice ?? serverPref.data ?? true;
31+
const [choice, setChoice] = useState<boolean | undefined>(readOpenBrowserPref);
32+
const open = choice ?? serverDefault;
4433

4534
return (
4635
<label className="open-browser-pref">

‎gui/src/components/provider-workspace/ProviderAuthPanel.tsx‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -410,7 +410,7 @@ export default function ProviderAuthPanel({
410410
)}
411411
</span>
412412
</div>
413-
{!busy && <OpenBrowserPrefToggle apiBase={apiBase} />}
413+
{!busy && <OpenBrowserPrefToggle />}
414414
{busy && hintForThis && (
415415
<div className="pwi-auth-wait">
416416
<span className="pwi-spin-inline" aria-hidden="true" />

0 commit comments

Comments
 (0)