GV

GeezerVison

The World Wide Web, restored to 800 pixels of glory.

Home|About|Gaming cabinet|Archives|How it works|Starter sites

On this site

  • Sign in
  • ActionsCI/CD and automation
  • CodespacesCloud development environments
  • All Features
  • Documentation
  • Training
  • Certifications
  • Build with Copilot
  • Customize Copilot
  • Integrations
  • Trending repos
  • GitHub Sponsors
  • Developer articles
  • Enterprises

This view

  • Original page
  • New address

GeezerVison is showing github.com — fix(web): clear the profile the menu names, and only that profile · pingdotgg/t3code@61d5a11

File tree

Expand file treeCollapse file tree
Open diff view settings
Filter options
  • apps
    • desktop/src
      • ipc/methods
        • preview.ts
      • preview
        • BrowserSession.test.ts
    • web/src
      • browser
        • previewWebviewConfigState.ts
      • components
        • preview
          • PreviewMoreMenu.tsx
          • PreviewView.tsx
        • ui
          • menu.tsx
  • packages/contracts/src
    • browserProfile.test.ts
    • browserProfile.ts
Expand file treeCollapse file tree
Open diff view settings
Collapse file

‎apps/desktop/src/ipc/methods/preview.ts‎

Copy file name to clipboardExpand all lines: apps/desktop/src/ipc/methods/preview.ts
+5Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -239,6 +239,11 @@ const resolveClearPartitions = Effect.fn("desktop.ipc.preview.resolveClearPartit
239239
) {
240240
if (profileId === undefined) return undefined;
241241
const { scope, persistent } = resolvePartitionScope(environmentId, profileId);
242+
// Loading the session is what puts the partition in the map the clear walks.
243+
// Deriving the partition string alone leaves nothing to match, so clearing a
244+
// profile with no tab open this run — after a restart, or when deleting a
245+
// profile — would report success and delete nothing.
246+
yield* manager.getBrowserSession(scope, persistent);
242247
return [yield* manager.getBrowserPartition(scope, persistent)];
243248
});
244249

Collapse file

‎apps/desktop/src/preview/BrowserSession.test.ts‎

Copy file name to clipboardExpand all lines: apps/desktop/src/preview/BrowserSession.test.ts
+22Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -192,6 +192,28 @@ describe("BrowserSession", () => {
192192
}).pipe(Effect.provide(layer)),
193193
);
194194

195+
it.effect("clears a partition whose session has not been opened yet", () =>
196+
Effect.gen(function* () {
197+
const browserSessions = yield* BrowserSession.BrowserSession;
198+
const partition = yield* browserSessions.getPartition("scope-untouched");
199+
200+
// Deriving the partition string does not create the session, and the
201+
// clear only walks sessions it already holds. Without loading it first
202+
// this reports success and deletes nothing — which is what a user
203+
// clearing a profile after a restart would get.
204+
assert.isUndefined(sessions.get(partition));
205+
yield* browserSessions.clearCookies([partition]);
206+
assert.isUndefined(sessions.get(partition));
207+
208+
yield* browserSessions.getSession("scope-untouched");
209+
yield* browserSessions.clearCookies([partition]);
210+
211+
const created = sessions.get(partition);
212+
assert.isDefined(created);
213+
assert.strictEqual(created.clearStorageData.mock.calls.length, 1);
214+
}).pipe(Effect.provide(layer)),
215+
);
216+
195217
it.effect("correlates clear failures while still attempting every session", () =>
196218
Effect.gen(function* () {
197219
const browserSessions = yield* BrowserSession.BrowserSession;
Collapse file

‎apps/web/src/browser/previewWebviewConfigState.ts‎

Copy file name to clipboardExpand all lines: apps/web/src/browser/previewWebviewConfigState.ts
+12-3Lines changed: 12 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -62,14 +62,23 @@ export const loadPreviewWebviewConfig = (
6262
* `Atom.family` keys on its argument, so the environment and profile are
6363
* folded into one string: passing an object would allocate a fresh entry on
6464
* every render.
65+
*
66+
* The profile is the tail rather than a second field, so an id containing the
67+
* delimiter round-trips whole instead of being truncated into a different
68+
* profile's key. `BrowserProfileId` rejects control characters, which is what
69+
* makes the environment side of the split unambiguous.
6570
*/
71+
const CONFIG_KEY_DELIMITER = "\u0000";
72+
6673
const configKey = (environmentId: EnvironmentId, profileId: string | undefined): string =>
67-
`${environmentId}\u0000${profileId ?? ""}`;
74+
`${environmentId}${CONFIG_KEY_DELIMITER}${profileId ?? ""}`;
6875

6976
const parseConfigKey = (key: string): { environmentId: EnvironmentId; profileId?: string } => {
70-
const [environmentId = "", profileId = ""] = key.split("\u0000");
77+
const delimiter = key.indexOf(CONFIG_KEY_DELIMITER);
78+
const environmentId = (delimiter === -1 ? key : key.slice(0, delimiter)) as EnvironmentId;
79+
const profileId = delimiter === -1 ? "" : key.slice(delimiter + CONFIG_KEY_DELIMITER.length);
7180
return {
72-
environmentId: environmentId as EnvironmentId,
81+
environmentId,
7382
...(profileId === "" ? {} : { profileId }),
7483
};
7584
};
Collapse file

‎apps/web/src/components/preview/PreviewMoreMenu.tsx‎

Copy file name to clipboardExpand all lines: apps/web/src/components/preview/PreviewMoreMenu.tsx
+6-1Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -55,7 +55,12 @@ interface Props {
5555
/** Environment the tab belongs to; scopes storage clearing to its partitions. */
5656
environmentId: EnvironmentId;
5757
/** Profile the tab was opened under, if the server recorded one. */
58-
profileId: string | undefined;
58+
/**
59+
* Required: the IPC layer reads an absent profile as "every profile", so a
60+
* tab whose own profile is unknown must resolve the default before it gets
61+
* here rather than passing the gap along.
62+
*/
63+
profileId: string;
5964
/** Profile display name, shown so the menu says which data is being cleared. */
6065
profileName: string | undefined;
6166
}
Collapse file

‎apps/web/src/components/preview/PreviewView.tsx‎

Copy file name to clipboardExpand all lines: apps/web/src/components/preview/PreviewView.tsx
+6-4Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -146,9 +146,11 @@ export function PreviewView({
146146
const loadProgress = useLoadingProgress(loading);
147147
const viewport = snapshot?.viewport ?? FILL_PREVIEW_VIEWPORT;
148148
const browserDefaults = useBrowserDefaults();
149-
const activeProfile = browserDefaults.profiles.find(
150-
(profile) => profile.id === (snapshot?.profileId ?? browserDefaults.profileId),
151-
);
149+
// A tab created before profiles existed carries no profile of its own, so it
150+
// runs in — and must clear — the configured default. Passing the snapshot's
151+
// raw `undefined` through would reach the IPC layer as "every profile".
152+
const activeProfileId = snapshot?.profileId ?? browserDefaults.profileId;
153+
const activeProfile = browserDefaults.profiles.find((profile) => profile.id === activeProfileId);
152154
const panelRect = useBrowserSurfaceStore((state) =>
153155
runtimeTabId ? (state.byTabId[runtimeTabId]?.rect ?? null) : null,
154156
);
@@ -704,7 +706,7 @@ export function PreviewView({
704706
previewBridge ? (
705707
<PreviewMoreMenu
706708
environmentId={threadRef.environmentId}
707-
profileId={snapshot?.profileId}
709+
profileId={activeProfileId}
708710
profileName={activeProfile?.name}
709711
tabId={runtimeTabId}
710712
hasWebContents={desktopOverlay?.hasWebContents ?? false}
Collapse file

‎apps/web/src/components/ui/menu.tsx‎

Copy file name to clipboardExpand all lines: apps/web/src/components/ui/menu.tsx
+5-1Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -235,7 +235,11 @@ function MenuSubTrigger({
235235
return (
236236
<MenuPrimitive.SubmenuTrigger
237237
className={cn(
238-
"flex min-h-8 cursor-pointer items-center gap-2 rounded-sm px-2 py-1 text-base text-foreground outline-none data-disabled:cursor-not-allowed data-disabled:pointer-events-none data-highlighted:bg-accent data-popup-open:bg-accent data-inset:ps-8 data-highlighted:text-accent-foreground data-popup-open:text-accent-foreground data-disabled:opacity-64 sm:min-h-7 sm:text-sm [&_svg:not([class*='size-'])]:size-4.5 sm:[&_svg:not([class*='size-'])]:size-4 [&_svg:not([class*='text-'])]:text-muted-foreground [&_svg]:pointer-events-none",
238+
// Leading-icon treatment matches `MenuItem`: a sub-trigger sits in the
239+
// same column as the items around it, so its icon has to align and dim
240+
// with theirs. Scoped to the first svg because the chevron below is
241+
// also a direct child, and `-mx-0.5` would override its `-me-0.5`.
242+
"[&>svg:first-of-type]:-mx-0.5 flex min-h-8 cursor-pointer items-center gap-2 rounded-sm px-2 py-1 text-base text-foreground outline-none data-disabled:cursor-not-allowed data-disabled:pointer-events-none data-highlighted:bg-accent data-popup-open:bg-accent data-inset:ps-8 data-highlighted:text-accent-foreground data-popup-open:text-accent-foreground data-disabled:opacity-64 sm:min-h-7 sm:text-sm [&_svg:not([class*='size-'])]:size-4.5 sm:[&_svg:not([class*='size-'])]:size-4 [&_svg:not([class*='text-'])]:text-muted-foreground [&>svg:first-of-type:not([class*='opacity-'])]:opacity-80 [&_svg]:pointer-events-none [&>svg]:shrink-0",
239243
className,
240244
)}
241245
data-inset={inset}
Collapse file

‎packages/contracts/src/browserProfile.test.ts‎

Copy file name to clipboardExpand all lines: packages/contracts/src/browserProfile.test.ts
+50Lines changed: 50 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,9 @@
11
import { describe, expect, it } from "@effect/vitest";
22

3+
import { Schema } from "effect";
4+
35
import {
6+
BrowserProfileId,
47
BUILT_IN_BROWSER_PROFILES,
58
DEFAULT_BROWSER_PROFILE_ID,
69
INCOGNITO_BROWSER_PROFILE_ID,
@@ -59,3 +62,50 @@ describe("isBuiltInBrowserProfileId", () => {
5962
expect(isBuiltInBrowserProfileId(work.id)).toBe(false);
6063
});
6164
});
65+
66+
describe("resolveBrowserProfiles normalization", () => {
67+
it("keeps only the first entry for a repeated id", () => {
68+
// Both map to the same Electron partition, so presenting two would offer
69+
// isolated identities that in fact share every cookie.
70+
const resolved = resolveBrowserProfiles([
71+
{ id: "work", name: "Work", kind: "persistent" },
72+
{ id: "work", name: "Work (old)", kind: "persistent" },
73+
]);
74+
75+
expect(resolved.filter((profile) => profile.id === "work")).toEqual([
76+
{ id: "work", name: "Work", kind: "persistent" },
77+
]);
78+
});
79+
80+
it("reports a custom incognito profile as persistent", () => {
81+
// Partition persistence is keyed off the built-in incognito id alone, so
82+
// a custom profile claiming that kind keeps its cookies across restarts.
83+
// Labelling it ephemeral would be a promise the partition layer breaks.
84+
const resolved = resolveBrowserProfiles([
85+
{ id: "throwaway", name: "Throwaway", kind: "incognito" },
86+
]);
87+
88+
expect(resolved.find((profile) => profile.id === "throwaway")).toEqual({
89+
id: "throwaway",
90+
name: "Throwaway",
91+
kind: "persistent",
92+
});
93+
});
94+
95+
it("still lets the built-in incognito profile stay ephemeral", () => {
96+
const incognito = resolveBrowserProfiles([]).find(
97+
(profile) => profile.id === INCOGNITO_BROWSER_PROFILE_ID,
98+
);
99+
100+
expect(incognito?.kind).toBe("incognito");
101+
});
102+
});
103+
104+
describe("BrowserProfileId", () => {
105+
it("rejects control characters", () => {
106+
// Ids are folded into delimiter-joined cache keys on the client, so one
107+
// carrying the delimiter would resolve to another profile's partition.
108+
expect(Schema.is(BrowserProfileId)("profile-a\u0000b")).toBe(false);
109+
expect(Schema.is(BrowserProfileId)("profile-a")).toBe(true);
110+
});
111+
});
Collapse file

‎packages/contracts/src/browserProfile.ts‎

Copy file name to clipboardExpand all lines: packages/contracts/src/browserProfile.ts
+29-8Lines changed: 29 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,15 @@ import { TrimmedNonEmptyString } from "./baseSchemas.ts";
1919
export const BROWSER_PROFILE_NAME_MAX_LENGTH = 48;
2020
export const BROWSER_PROFILE_MAX_COUNT = 24;
2121

22-
export const BrowserProfileId = TrimmedNonEmptyString.check(Schema.isMaxLength(64));
22+
/**
23+
* Control characters are rejected because ids are folded into delimiter-joined
24+
* cache keys on the client; one carrying the delimiter would resolve to a
25+
* different profile's partition.
26+
*/
27+
export const BrowserProfileId = TrimmedNonEmptyString.check(
28+
Schema.isMaxLength(64),
29+
Schema.isPattern(/^[^\p{Cc}]+$/u),
30+
);
2331
export type BrowserProfileId = typeof BrowserProfileId.Type;
2432

2533
export const BrowserProfileName = TrimmedNonEmptyString.check(
@@ -57,17 +65,30 @@ export function isBuiltInBrowserProfileId(id: string): boolean {
5765
}
5866

5967
/**
60-
* The full picker list: built-ins first, then the user's own profiles with any
61-
* entry that collides with a built-in id dropped, so a hand-edited settings
62-
* file cannot shadow "Default" or "Incognito".
68+
* The full picker list: built-ins first, then the user's own profiles.
69+
*
70+
* Three things are normalized away, because each would present a profile the
71+
* partition layer does not actually deliver:
72+
*
73+
* - Entries colliding with a built-in id, so a hand-edited settings file
74+
* cannot shadow "Default" or "Incognito".
75+
* - Repeated ids, which map to one partition and would otherwise appear as
76+
* two isolated identities sharing every cookie. First entry wins.
77+
* - `kind: "incognito"` on anything but the built-in, since persistence is
78+
* keyed off that one id; such a profile is labelled ephemeral while its
79+
* cookies survive restarts.
6380
*/
6481
export function resolveBrowserProfiles(
6582
userProfiles: ReadonlyArray<BrowserProfile>,
6683
): ReadonlyArray<BrowserProfile> {
67-
return [
68-
...BUILT_IN_BROWSER_PROFILES,
69-
...userProfiles.filter((profile) => !isBuiltInBrowserProfileId(profile.id)),
70-
];
84+
const seen = new Set(BUILT_IN_BROWSER_PROFILES.map((profile) => profile.id));
85+
const resolved = [...BUILT_IN_BROWSER_PROFILES];
86+
for (const profile of userProfiles) {
87+
if (seen.has(profile.id)) continue;
88+
seen.add(profile.id);
89+
resolved.push(profile.kind === "persistent" ? profile : { ...profile, kind: "persistent" });
90+
}
91+
return resolved;
7192
}
7293

7394
export function findBrowserProfile(

0 commit comments

Comments
0 (0)
You are visitor 01402792 — GeezerVison does not store the pages you look up.
Best viewed with Netscape Navigator 4.7 or Internet Explorer 6 at 800×600. No cookies required.