GeezerVison is showing github.com — fix(web): clear the profile the menu names, and only that profile · pingdotgg/t3code@61d5a11
File treeExpand file treeCollapse file tree Open diff view settings Expand file treeCollapse file tree Open diff view settings Collapse file Copy file name to clipboardExpand all lines: apps/desktop/src/ipc/methods/preview.ts +5Lines changed: 5 additions & 0 deletions | Original file line number | Diff line number | Diff line change |
|---|
@@ -239,6 +239,11 @@ const resolveClearPartitions = Effect.fn("desktop.ipc.preview.resolveClearPartit | 239 | 239 | ) { | 240 | 240 | if (profileId === undefined) return undefined; | 241 | 241 | 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); | 242 | 247 | return [yield* manager.getBrowserPartition(scope, persistent)]; | 243 | 248 | }); | 244 | 249 |
| |
Collapse file Copy file name to clipboardExpand all lines: apps/desktop/src/preview/BrowserSession.test.ts +22Lines changed: 22 additions & 0 deletions | Original file line number | Diff line number | Diff line change |
|---|
@@ -192,6 +192,28 @@ describe("BrowserSession", () => { | 192 | 192 | }).pipe(Effect.provide(layer)), | 193 | 193 | ); | 194 | 194 |
| | 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 | + | 195 | 217 | it.effect("correlates clear failures while still attempting every session", () => | 196 | 218 | Effect.gen(function* () { | 197 | 219 | const browserSessions = yield* BrowserSession.BrowserSession; | |
Collapse file Copy file name to clipboardExpand all lines: apps/web/src/browser/previewWebviewConfigState.ts +12-3Lines changed: 12 additions & 3 deletions | Original file line number | Diff line number | Diff line change |
|---|
@@ -62,14 +62,23 @@ export const loadPreviewWebviewConfig = ( | 62 | 62 | * `Atom.family` keys on its argument, so the environment and profile are | 63 | 63 | * folded into one string: passing an object would allocate a fresh entry on | 64 | 64 | * 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. | 65 | 70 | */ | | 71 | +const CONFIG_KEY_DELIMITER = "\u0000"; | | 72 | + | 66 | 73 | const configKey = (environmentId: EnvironmentId, profileId: string | undefined): string => | 67 | | - `${environmentId}\u0000${profileId ?? ""}`; | | 74 | + `${environmentId}${CONFIG_KEY_DELIMITER}${profileId ?? ""}`; | 68 | 75 |
| 69 | 76 | 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); | 71 | 80 | return { | 72 | | - environmentId: environmentId as EnvironmentId, | | 81 | + environmentId, | 73 | 82 | ...(profileId === "" ? {} : { profileId }), | 74 | 83 | }; | 75 | 84 | }; | |
Collapse file Copy file name to clipboardExpand all lines: apps/web/src/components/preview/PreviewMoreMenu.tsx +6-1Lines changed: 6 additions & 1 deletion | Original file line number | Diff line number | Diff line change |
|---|
@@ -55,7 +55,12 @@ interface Props { | 55 | 55 | /** Environment the tab belongs to; scopes storage clearing to its partitions. */ | 56 | 56 | environmentId: EnvironmentId; | 57 | 57 | /** 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; | 59 | 64 | /** Profile display name, shown so the menu says which data is being cleared. */ | 60 | 65 | profileName: string | undefined; | 61 | 66 | } | |
Collapse file Copy file name to clipboardExpand all lines: apps/web/src/components/preview/PreviewView.tsx +6-4Lines changed: 6 additions & 4 deletions | Original file line number | Diff line number | Diff line change |
|---|
@@ -146,9 +146,11 @@ export function PreviewView({ | 146 | 146 | const loadProgress = useLoadingProgress(loading); | 147 | 147 | const viewport = snapshot?.viewport ?? FILL_PREVIEW_VIEWPORT; | 148 | 148 | 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); | 152 | 154 | const panelRect = useBrowserSurfaceStore((state) => | 153 | 155 | runtimeTabId ? (state.byTabId[runtimeTabId]?.rect ?? null) : null, | 154 | 156 | ); | @@ -704,7 +706,7 @@ export function PreviewView({ | 704 | 706 | previewBridge ? ( | 705 | 707 | <PreviewMoreMenu | 706 | 708 | environmentId={threadRef.environmentId} | 707 | | - profileId={snapshot?.profileId} | | 709 | + profileId={activeProfileId} | 708 | 710 | profileName={activeProfile?.name} | 709 | 711 | tabId={runtimeTabId} | 710 | 712 | hasWebContents={desktopOverlay?.hasWebContents ?? false} | |
Collapse file Copy file name to clipboardExpand all lines: apps/web/src/components/ui/menu.tsx +5-1Lines changed: 5 additions & 1 deletion | Original file line number | Diff line number | Diff line change |
|---|
@@ -235,7 +235,11 @@ function MenuSubTrigger({ | 235 | 235 | return ( | 236 | 236 | <MenuPrimitive.SubmenuTrigger | 237 | 237 | 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", | 239 | 243 | className, | 240 | 244 | )} | 241 | 245 | data-inset={inset} | |
Collapse file Copy file name to clipboardExpand all lines: packages/contracts/src/browserProfile.test.ts +50Lines changed: 50 additions & 0 deletions | Original file line number | Diff line number | Diff line change |
|---|
| 1 | 1 | import { describe, expect, it } from "@effect/vitest"; | 2 | 2 |
| | 3 | +import { Schema } from "effect"; | | 4 | + | 3 | 5 | import { | | 6 | + BrowserProfileId, | 4 | 7 | BUILT_IN_BROWSER_PROFILES, | 5 | 8 | DEFAULT_BROWSER_PROFILE_ID, | 6 | 9 | INCOGNITO_BROWSER_PROFILE_ID, | @@ -59,3 +62,50 @@ describe("isBuiltInBrowserProfileId", () => { | 59 | 62 | expect(isBuiltInBrowserProfileId(work.id)).toBe(false); | 60 | 63 | }); | 61 | 64 | }); | | 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 Copy file name to clipboardExpand all lines: packages/contracts/src/browserProfile.ts +29-8Lines changed: 29 additions & 8 deletions | Original file line number | Diff line number | Diff line change |
|---|
@@ -19,7 +19,15 @@ import { TrimmedNonEmptyString } from "./baseSchemas.ts"; | 19 | 19 | export const BROWSER_PROFILE_NAME_MAX_LENGTH = 48; | 20 | 20 | export const BROWSER_PROFILE_MAX_COUNT = 24; | 21 | 21 |
| 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 | +); | 23 | 31 | export type BrowserProfileId = typeof BrowserProfileId.Type; | 24 | 32 |
| 25 | 33 | export const BrowserProfileName = TrimmedNonEmptyString.check( | @@ -57,17 +65,30 @@ export function isBuiltInBrowserProfileId(id: string): boolean { | 57 | 65 | } | 58 | 66 |
| 59 | 67 | /** | 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. | 63 | 80 | */ | 64 | 81 | export function resolveBrowserProfiles( | 65 | 82 | userProfiles: ReadonlyArray<BrowserProfile>, | 66 | 83 | ): 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; | 71 | 92 | } | 72 | 93 |
| 73 | 94 | export function findBrowserProfile( | |
|