Skip to content

Commit e6119fd

Browse files
fix(web): browser settings changed in project scope no longer overwrite the global default (pingdotgg#35143)
1 parent 5574cca commit e6119fd

6 files changed

Lines changed: 58 additions & 17 deletions

File tree

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

Lines changed: 11 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -322,7 +322,7 @@ const rotateViewport = (
322322

323323
function BrowserViewportSetting({ disabled }: { readonly disabled: boolean }) {
324324
const viewport = useClientSettings((settings) => settings.browserDefaultViewport);
325-
const updateSettings = useUpdatePrimarySettings();
325+
const updateSettings = useUpdateScopedSettings();
326326

327327
const sized = viewport._tag === "fill" ? null : viewport;
328328
const presentedSize = {
@@ -472,7 +472,7 @@ function BrowserViewportSetting({ disabled }: { readonly disabled: boolean }) {
472472

473473
function BrowserZoomSetting({ disabled }: { readonly disabled: boolean }) {
474474
const zoomFactor = useClientSettings((settings) => settings.browserDefaultZoomFactor);
475-
const updateSettings = useUpdatePrimarySettings();
475+
const updateSettings = useUpdateScopedSettings();
476476

477477
return (
478478
<SettingsRow
@@ -515,7 +515,7 @@ function BrowserZoomSetting({ disabled }: { readonly disabled: boolean }) {
515515

516516
function BrowserAppearanceSetting({ disabled }: { readonly disabled: boolean }) {
517517
const appearance = useClientSettings((settings) => settings.browserDefaultAppearance);
518-
const updateSettings = useUpdatePrimarySettings();
518+
const updateSettings = useUpdateScopedSettings();
519519

520520
return (
521521
<SettingsRow
@@ -562,7 +562,7 @@ function BrowserAppearanceSetting({ disabled }: { readonly disabled: boolean })
562562
function BrowserRecordingInputSettings({ disabled }: { readonly disabled: boolean }) {
563563
const showKeys = useClientSettings((settings) => settings.browserRecordingShowKeyPresses);
564564
const showMouse = useClientSettings((settings) => settings.browserRecordingShowMousePresses);
565-
const updateSettings = useUpdatePrimarySettings();
565+
const updateSettings = useUpdateScopedSettings();
566566
return (
567567
<>
568568
<SettingsRow
@@ -599,7 +599,7 @@ function BrowserRecordingInputSettings({ disabled }: { readonly disabled: boolea
599599

600600
function BrowserRecordingFrameRateSetting({ disabled }: { readonly disabled: boolean }) {
601601
const frameRate = useClientSettings((settings) => settings.browserRecordingFrameRate);
602-
const updateSettings = useUpdatePrimarySettings();
602+
const updateSettings = useUpdateScopedSettings();
603603

604604
return (
605605
<SettingsRow
@@ -653,7 +653,7 @@ const LINK_TARGET_LABELS: Readonly<Record<BrowserLinkTarget, string>> = {
653653

654654
function BrowserLinkTargetSetting({ disabled }: { readonly disabled: boolean }) {
655655
const linkTarget = useClientSettings((settings) => settings.browserLinkTarget);
656-
const updateSettings = useUpdatePrimarySettings();
656+
const updateSettings = useUpdateScopedSettings();
657657

658658
return (
659659
<SettingsRow
@@ -706,7 +706,7 @@ const SEARCH_ENGINE_LABELS: Readonly<Record<BrowserSearchEngine, string>> = {
706706
function BrowserSearchEngineSetting() {
707707
const engine = useClientSettings((settings) => settings.browserSearchEngine);
708708
const customUrl = useClientSettings((settings) => settings.browserCustomSearchUrl);
709-
const updateSettings = useUpdatePrimarySettings();
709+
const updateSettings = useUpdateScopedSettings();
710710

711711
return (
712712
<>
@@ -1075,7 +1075,7 @@ function AgentBrowserAccessSetting() {
10751075

10761076
function BrowserAutoShowFloatingPreviewSetting({ disabled }: { readonly disabled: boolean }) {
10771077
const autoShow = useClientSettings((settings) => settings.browserAutoShowFloatingPreview);
1078-
const updateSettings = useUpdatePrimarySettings();
1078+
const updateSettings = useUpdateScopedSettings();
10791079

10801080
return (
10811081
<SettingsRow
@@ -1111,7 +1111,9 @@ function BrowserProfilesSetting({ disabled }: { readonly disabled: boolean }) {
11111111
const userProfiles = useClientSettings((settings) => settings.browserProfiles);
11121112
const defaultProfileId = useClientSettings((settings) => settings.browserDefaultProfileId);
11131113
const settingsHydrated = useClientSettingsHydrated();
1114+
// Profile edits pair with profile data on disk, so they save for this device in every scope.
11141115
const updateSettings = useUpdatePrimarySettings();
1116+
const updateDefaultProfile = useUpdateScopedSettings();
11151117
const { environments, isReady: environmentsReady } = useEnvironments();
11161118
const primaryEnvironment = usePrimaryEnvironment();
11171119
// Cookie import runs on this desktop, whose policy the primary environment reports.
@@ -1422,7 +1424,7 @@ function BrowserProfilesSetting({ disabled }: { readonly disabled: boolean }) {
14221424
disabled={!settingsHydrated || isDefault}
14231425
onClick={() => {
14241426
if (settingsHydrated) {
1425-
updateSettings({ browserDefaultProfileId: profile.id });
1427+
updateDefaultProfile({ browserDefaultProfileId: profile.id });
14261428
}
14271429
}}
14281430
>

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

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -85,6 +85,7 @@ function useResolvedSettingsScope(rawSearch: SettingsScopeSearch, singleEnvironm
8585
const SettingsScopeContext = createContext<
8686
| (ReturnType<typeof useResolvedSettingsScope> & {
8787
singleEnvironment: boolean;
88+
deviceOnly: boolean;
8889
search: SettingsScopeSearch;
8990
selectScope: (next: SettingsScopeSearch) => void;
9091
})
@@ -96,14 +97,17 @@ export function SettingsScopeProvider({
9697
onChange,
9798
children,
9899
singleEnvironment = false,
100+
deviceOnly = false,
99101
}: {
100102
singleEnvironment?: boolean;
103+
/** The page hides the scope picker, so its client settings save for this device. */
104+
deviceOnly?: boolean;
101105
search: SettingsScopeSearch;
102106
onChange: (next: SettingsScopeSearch) => void;
103107
children: ReactNode;
104108
}) {
105109
const resolved = useResolvedSettingsScope(search, singleEnvironment);
106-
const value = { ...resolved, singleEnvironment, selectScope: onChange };
110+
const value = { ...resolved, singleEnvironment, deviceOnly, selectScope: onChange };
107111
return <SettingsScopeContext value={value}>{children}</SettingsScopeContext>;
108112
}
109113

‎apps/web/src/components/settings/scopedSettings.test.ts‎

Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -467,6 +467,31 @@ describe("scoped settings writes", () => {
467467
});
468468
});
469469

470+
// regression: #35093 client settings saved in project scope overwrote the global default
471+
it("refuses client-only keys at project scope", () => {
472+
for (const scope of [project, checkout]) {
473+
expect(
474+
planScopedSettingsPatch(scope, environments, {
475+
browserDefaultViewport: { _tag: "freeform", width: 1440, height: 900 },
476+
}),
477+
).toMatchObject({
478+
clientPatch: {},
479+
hasClientWrite: false,
480+
serverWrites: [],
481+
unavailableReason:
482+
"This setting is environment-wide and cannot be overridden by a project.",
483+
});
484+
expect(
485+
planScopedSettingsPatch(
486+
scope,
487+
environments,
488+
{ fontSizeInterface: 15 },
489+
{ deviceOnly: true },
490+
),
491+
).toMatchObject({ clientPatch: { fontSizeInterface: 15 }, unavailableReason: null });
492+
}
493+
});
494+
470495
it("clears overrides per member and removes an emptied entry", () => {
471496
const withOverrides = environment("Server", {
472497
settings: {

‎apps/web/src/components/settings/scopedSettings.ts‎

Lines changed: 14 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -221,19 +221,28 @@ export function planScopedSettingsPatch(
221221
scope: ResolvedSettingsScope,
222222
environments: readonly ScopedSettingsEnvironment[],
223223
patch: ScopedSettingsPatch,
224+
options?: { readonly deviceOnly?: boolean },
224225
) {
225-
const clientPatch = Object.fromEntries(
226-
Object.entries(patch).filter(([key]) => CLIENT_KEYS.has(key) && !SERVER_KEYS.has(key)),
227-
) as ClientSettingsPatch;
226+
const isProjectScope = scope.kind === "project" || scope.kind === "checkout";
227+
const refusesClientKeys = isProjectScope && options?.deviceOnly !== true;
228+
const clientKeys = Object.keys(patch).filter(
229+
(key) => CLIENT_KEYS.has(key) && !SERVER_KEYS.has(key),
230+
);
228231
const serverPatch = Object.fromEntries(
229232
Object.entries(patch).filter(([key]) => SERVER_KEYS.has(key)),
230233
) as ServerSettingsPatch;
231234
const serverKeys = Object.keys(serverPatch);
232235
const { connectedEnvironments } = selectScopedSettingsEnvironments(scope, environments, null);
233-
const isProjectScope = scope.kind === "project" || scope.kind === "checkout";
236+
// Client settings are stored per device, so a project has nowhere to keep an override.
234237
const unscopableKeys = isProjectScope
235-
? serverKeys.filter((key) => !isProjectScopedSettingKey(key))
238+
? [
239+
...(refusesClientKeys ? clientKeys : []),
240+
...serverKeys.filter((key) => !isProjectScopedSettingKey(key)),
241+
]
236242
: [];
243+
const clientPatch = Object.fromEntries(
244+
refusesClientKeys ? [] : Object.entries(patch).filter(([key]) => clientKeys.includes(key)),
245+
) as ClientSettingsPatch;
237246
const serverWrites: ScopedServerWrite[] =
238247
serverKeys.length === 0
239248
? []

‎apps/web/src/components/settings/useScopedSettings.ts‎

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -98,11 +98,11 @@ function useRunScopedPlan() {
9898
}
9999

100100
export function useUpdateScopedSettings() {
101-
const { scope, environments } = useSettingsScope();
101+
const { scope, environments, deviceOnly } = useSettingsScope();
102102
const run = useRunScopedPlan();
103103
/** `onFailed` runs when any target rejects or drops the patch, so a draft can fall back. */
104104
return (patch: ScopedSettingsPatch, options?: { readonly onFailed?: () => void }) =>
105-
run(planScopedSettingsPatch(scope, environments, patch), options?.onFailed);
105+
run(planScopedSettingsPatch(scope, environments, patch, { deviceOnly }), options?.onFailed);
106106
}
107107

108108
export function useClearScopedSettings() {

‎apps/web/src/routes/_chat.settings.tsx‎

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -151,6 +151,7 @@ function SettingsRouteLayout() {
151151
<SettingsScopeProvider
152152
search={rawSearch}
153153
singleEnvironment={pathname === "/settings/providers" || pathname === "/settings/secrets"}
154+
deviceOnly={SETTINGS_DEVICE_ONLY_PATHS.has(pathname)}
154155
onChange={(next) => {
155156
// Send every axis so retain middleware recognizes "all" as an explicit target.
156157
void navigate({

0 commit comments

Comments
 (0)