Skip to content

Commit 1d8e405

Browse files
committed
fix(web): keep incognito visits out of project browser history
1 parent ac8dce0 commit 1d8e405

5 files changed

Lines changed: 135 additions & 48 deletions

File tree

‎apps/web/src/browserHistoryStore.test.ts‎

Lines changed: 103 additions & 31 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,9 @@ import { afterEach, beforeEach, describe, expect, it, vi } from "vite-plus/test"
22

33
import { scopeProjectRef } from "@t3tools/client-runtime/environment";
44
import {
5+
DEFAULT_BROWSER_PROFILE_ID,
56
EnvironmentId,
7+
INCOGNITO_BROWSER_PROFILE_ID,
68
type PreviewSessionSnapshot,
79
ProjectId,
810
ThreadId,
@@ -157,11 +159,18 @@ const threadRef = {
157159

158160
let settledAt = 0;
159161

160-
function settle(url: string, title: string, tabId = "tab_a", ref = threadRef): void {
162+
function settle(
163+
url: string,
164+
title: string,
165+
tabId = "tab_a",
166+
ref = threadRef,
167+
profileId?: string,
168+
): void {
161169
settledAt += 1;
162170
const snapshot: PreviewSessionSnapshot = {
163171
threadId: ref.threadId,
164172
tabId,
173+
...(profileId === undefined ? {} : { profileId }),
165174
navStatus: { _tag: "Success", url, title },
166175
canGoBack: false,
167176
canGoForward: false,
@@ -179,20 +188,83 @@ function resetStores(): () => void {
179188
describe("useBrowserHistoryStore", () => {
180189
beforeEach(resetStores);
181190

191+
it.each([false, true])(
192+
"excludes incognito visits from saved history with project already registered: %s",
193+
async (registered) => {
194+
if (registered) useBrowserHistoryStore.getState().registerThreadProject(threadRef, "proj-a");
195+
recordVisitForThread(
196+
threadRef,
197+
"https://private.example/unique",
198+
INCOGNITO_BROWSER_PROFILE_ID,
199+
1,
200+
);
201+
expect(useBrowserHistoryStore.getState().pendingVisitsByThreadKey).toEqual({});
202+
useBrowserHistoryStore.getState().registerThreadProject(threadRef, "proj-a");
203+
for (const [index, profileId] of [undefined, DEFAULT_BROWSER_PROFILE_ID, "work"].entries()) {
204+
recordVisitForThread(threadRef, `https://public.example/${index}`, profileId, index + 2);
205+
}
206+
expect(
207+
useBrowserHistoryStore.getState().byProjectKey["proj-a"]?.map((entry) => entry.url),
208+
).toEqual([
209+
"https://public.example/2",
210+
"https://public.example/1",
211+
"https://public.example/0",
212+
]);
213+
const { storage, name } = useBrowserHistoryStore.persist.getOptions();
214+
const saved = JSON.stringify(await storage!.getItem(name!));
215+
expect(saved).not.toContain("private.example");
216+
expect(saved).toContain("public.example");
217+
await useBrowserHistoryStore.persist.rehydrate();
218+
expect(
219+
useBrowserHistoryStore.getState().byProjectKey["proj-a"]?.map((entry) => entry.url),
220+
).toEqual([
221+
"https://public.example/2",
222+
"https://public.example/1",
223+
"https://public.example/0",
224+
]);
225+
},
226+
);
227+
228+
it.each([false, true])(
229+
"excludes incognito titles from regular history with page settled before visit: %s",
230+
async (settledBeforeVisit) => {
231+
useBrowserHistoryStore.getState().registerThreadProject(threadRef, "proj-a");
232+
if (!settledBeforeVisit) {
233+
recordVisitForThread(threadRef, "http://a.test/", undefined, 1);
234+
settle("http://a.test/", "Public page");
235+
}
236+
settle(
237+
"http://a.test/",
238+
"Private page",
239+
"private-tab",
240+
threadRef,
241+
INCOGNITO_BROWSER_PROFILE_ID,
242+
);
243+
if (settledBeforeVisit) recordVisitForThread(threadRef, "http://a.test/", undefined, 1);
244+
expect(useBrowserHistoryStore.getState().byProjectKey["proj-a"]?.[0]?.title).toBe(
245+
settledBeforeVisit ? undefined : "Public page",
246+
);
247+
const { storage, name } = useBrowserHistoryStore.persist.getOptions();
248+
expect(JSON.stringify(await storage!.getItem(name!))).not.toContain("Private page");
249+
settle("http://a.test/", "Work page", "work-tab", threadRef, "work");
250+
expect(JSON.stringify(await storage!.getItem(name!))).toContain("Work page");
251+
},
252+
);
253+
182254
it("titles only pages already in history when they settle", () => {
183255
useBrowserHistoryStore.getState().registerThreadProject(threadRef, "proj-a");
184256
settle("http://a.test/", "Should not create");
185257
expect(useBrowserHistoryStore.getState().byProjectKey).toEqual({});
186-
recordVisitForThread(threadRef, "http://a.test/#/settings", 1);
258+
recordVisitForThread(threadRef, "http://a.test/#/settings", undefined, 1);
187259
settle("http://a.test/#/settings", "My App");
188260
expect(useBrowserHistoryStore.getState().byProjectKey["proj-a"]?.[0]?.title).toBe("My App");
189261
});
190262

191263
it("titles a visit recorded after its page already settled", () => {
192264
useBrowserHistoryStore.getState().registerThreadProject(threadRef, "proj-a");
193-
recordVisitForThread(threadRef, "http://other.test/", 1);
265+
recordVisitForThread(threadRef, "http://other.test/", undefined, 1);
194266
settle("http://a.test/", "My App");
195-
recordVisitForThread(threadRef, "http://a.test/", 2);
267+
recordVisitForThread(threadRef, "http://a.test/", undefined, 2);
196268
expect(useBrowserHistoryStore.getState().byProjectKey["proj-a"]?.[0]).toMatchObject({
197269
url: "http://a.test/",
198270
title: "My App",
@@ -201,7 +273,7 @@ describe("useBrowserHistoryStore", () => {
201273

202274
it("keeps the newest title when another tab shows the same url", () => {
203275
useBrowserHistoryStore.getState().registerThreadProject(threadRef, "proj-a");
204-
recordVisitForThread(threadRef, "http://a.test/", 1);
276+
recordVisitForThread(threadRef, "http://a.test/", undefined, 1);
205277
settle("http://a.test/", "Old", "tab_a");
206278
settle("http://a.test/", "Old", "tab_b");
207279
settle("http://a.test/", "New", "tab_a");
@@ -213,7 +285,7 @@ describe("useBrowserHistoryStore", () => {
213285
const store = useBrowserHistoryStore.getState();
214286
store.registerThreadProject(threadRef, "proj-a");
215287
store.registerThreadProject(otherThreadRef, "proj-a");
216-
recordVisitForThread(threadRef, "http://a.test/", 1);
288+
recordVisitForThread(threadRef, "http://a.test/", undefined, 1);
217289
settle("http://a.test/", "Old", "tab_a", threadRef);
218290
settle("http://a.test/", "New", "tab_a", otherThreadRef);
219291
settle("http://b.test/", "Unrelated", "tab_b", threadRef);
@@ -229,10 +301,10 @@ describe("useBrowserHistoryStore", () => {
229301
const store = useBrowserHistoryStore.getState();
230302
store.registerThreadProject(threadRef, "proj-a");
231303
store.registerThreadProject(otherThreadRef, "proj-a");
232-
recordVisitForThread(threadRef, "http://a.test/", 1);
304+
recordVisitForThread(threadRef, "http://a.test/", undefined, 1);
233305
settle("http://a.test/", "Old", "tab_a", threadRef);
234306
settle("http://a.test/", "New", "tab_a", otherThreadRef);
235-
recordVisitForThread(threadRef, "http://b.test/", 2);
307+
recordVisitForThread(threadRef, "http://b.test/", undefined, 2);
236308
expect(
237309
useBrowserHistoryStore
238310
.getState()
@@ -245,7 +317,7 @@ describe("useBrowserHistoryStore", () => {
245317
const store = useBrowserHistoryStore.getState();
246318
store.registerThreadProject(threadRef, "proj-a");
247319
store.registerThreadProject(otherThreadRef, "proj-a");
248-
recordVisitForThread(threadRef, "http://a.test/", 1);
320+
recordVisitForThread(threadRef, "http://a.test/", undefined, 1);
249321
settle("http://a.test/", "Old", "tab_a", threadRef);
250322
settle("http://a.test/", "New", "tab_a", otherThreadRef);
251323
// A resize or a list reconcile replaces the session without a new page load.
@@ -258,24 +330,24 @@ describe("useBrowserHistoryStore", () => {
258330
const store = useBrowserHistoryStore.getState();
259331
store.registerThreadProject(threadRef, "proj-a");
260332
store.registerThreadProject(otherThreadRef, "proj-a");
261-
recordVisitForThread(threadRef, "http://a.test/", 1);
333+
recordVisitForThread(threadRef, "http://a.test/", undefined, 1);
262334
settle("http://a.test/", "Old", "tab_a", threadRef);
263335
settle("http://a.test/", "New", "tab_a", otherThreadRef);
264-
recordVisitForThread(threadRef, "http://a.test/", 2);
336+
recordVisitForThread(threadRef, "http://a.test/", undefined, 2);
265337
expect(useBrowserHistoryStore.getState().byProjectKey["proj-a"]?.[0]?.title).toBe("New");
266338
});
267339

268340
it("sets a title against a settled url that differs from the stored one only by a trailing slash", () => {
269341
useBrowserHistoryStore.getState().registerThreadProject(threadRef, "proj-a");
270-
recordVisitForThread(threadRef, "http://a.test/community", 1);
342+
recordVisitForThread(threadRef, "http://a.test/community", undefined, 1);
271343
settle("http://a.test/community/", "Community");
272344
expect(useBrowserHistoryStore.getState().byProjectKey["proj-a"]?.[0]).toMatchObject({
273345
url: "http://a.test/community",
274346
title: "Community",
275347
});
276348

277349
useBrowserHistoryStore.setState({ byProjectKey: {} });
278-
recordVisitForThread(threadRef, "http://a.test/community/", 1);
350+
recordVisitForThread(threadRef, "http://a.test/community/", undefined, 1);
279351
settle("http://a.test/community", "Community");
280352
expect(useBrowserHistoryStore.getState().byProjectKey["proj-a"]?.[0]).toMatchObject({
281353
url: "http://a.test/community/",
@@ -285,7 +357,7 @@ describe("useBrowserHistoryStore", () => {
285357

286358
it("matches a requested localhost URL to the resolved environment host", () => {
287359
useBrowserHistoryStore.getState().registerThreadProject(threadRef, "proj-a");
288-
recordVisitForThread(threadRef, "http://localhost:5173/app", 1);
360+
recordVisitForThread(threadRef, "http://localhost:5173/app", undefined, 1);
289361
readPreparedConnection.mockReturnValue({ httpBaseUrl: "http://192.168.64.2:3773" });
290362
settle("http://192.168.64.2:5173/app", "Local App");
291363
expect(useBrowserHistoryStore.getState().byProjectKey["proj-a"]?.[0]?.title).toBe("Local App");
@@ -294,16 +366,16 @@ describe("useBrowserHistoryStore", () => {
294366
it("deduplicates loopback aliases and the resolved environment host", () => {
295367
readPreparedConnection.mockReturnValue({ httpBaseUrl: "http://192.168.64.2:3773" });
296368
useBrowserHistoryStore.getState().registerThreadProject(threadRef, "proj-a");
297-
recordVisitForThread(threadRef, "http://localhost:5173/app", 1);
298-
recordVisitForThread(threadRef, "http://127.0.0.1:5173/app", 2);
299-
recordVisitForThread(threadRef, "http://192.168.64.2:5173/app", 3);
369+
recordVisitForThread(threadRef, "http://localhost:5173/app", undefined, 1);
370+
recordVisitForThread(threadRef, "http://127.0.0.1:5173/app", undefined, 2);
371+
recordVisitForThread(threadRef, "http://192.168.64.2:5173/app", undefined, 3);
300372
expect(useBrowserHistoryStore.getState().byProjectKey["proj-a"]).toEqual([
301373
{ url: "http://localhost:5173/app", lastVisitedAt: 3 },
302374
]);
303375

304376
useBrowserHistoryStore.setState({ byProjectKey: {} });
305-
recordVisitForThread(threadRef, "http://192.168.64.2:5173/app", 4);
306-
recordVisitForThread(threadRef, "http://localhost:5173/app", 5);
377+
recordVisitForThread(threadRef, "http://192.168.64.2:5173/app", undefined, 4);
378+
recordVisitForThread(threadRef, "http://localhost:5173/app", undefined, 5);
307379
expect(useBrowserHistoryStore.getState().byProjectKey["proj-a"]).toEqual([
308380
{ url: "http://localhost:5173/app", lastVisitedAt: 5 },
309381
]);
@@ -325,7 +397,7 @@ describe("thread project resolution", () => {
325397
entities.projects = [repoProject];
326398
entities.shellProjectId = "project-1";
327399

328-
recordVisitForThread(threadRef, "http://localhost:5173/", 1);
400+
recordVisitForThread(threadRef, "http://localhost:5173/", undefined, 1);
329401
settle("http://localhost:5173/", "Dev App");
330402

331403
expect(useBrowserHistoryStore.getState().byProjectKey).toEqual({
@@ -343,7 +415,7 @@ describe("thread project resolution", () => {
343415
threadId: threadRef.threadId,
344416
});
345417

346-
recordVisitForThread(threadRef, "http://localhost:5173/", 1);
418+
recordVisitForThread(threadRef, "http://localhost:5173/", undefined, 1);
347419

348420
expect(useBrowserHistoryStore.getState().byProjectKey).toEqual({
349421
"env-1:/repo": [{ url: "http://localhost:5173/", lastVisitedAt: 1 }],
@@ -362,7 +434,7 @@ describe("thread project resolution", () => {
362434
};
363435
});
364436

365-
recordVisitForThread(threadRef, "http://localhost:5173/", 1);
437+
recordVisitForThread(threadRef, "http://localhost:5173/", undefined, 1);
366438
expect(useBrowserHistoryStore.getState().projectKeyByThreadKey).toEqual({});
367439

368440
settingsHydration.finish();
@@ -374,10 +446,10 @@ describe("thread project resolution", () => {
374446
});
375447

376448
it("lands visits queued before the thread's project loaded with the next visit", () => {
377-
recordVisitForThread(threadRef, "http://a.test/", 1);
449+
recordVisitForThread(threadRef, "http://a.test/", undefined, 1);
378450
entities.projects = [repoProject];
379451
entities.shellProjectId = "project-1";
380-
recordVisitForThread(threadRef, "http://b.test/", 2);
452+
recordVisitForThread(threadRef, "http://b.test/", undefined, 2);
381453

382454
expect(
383455
useBrowserHistoryStore.getState().byProjectKey["env-1:/repo"]?.map((entry) => entry.url),
@@ -389,8 +461,8 @@ describe("pendingVisitsByThreadKey", () => {
389461
beforeEach(resetStores);
390462

391463
it("queues a visit recorded before registration and drains it in order on registration", () => {
392-
recordVisitForThread(threadRef, "http://a.test/", 1);
393-
recordVisitForThread(threadRef, "http://b.test/", 2);
464+
recordVisitForThread(threadRef, "http://a.test/", undefined, 1);
465+
recordVisitForThread(threadRef, "http://b.test/", undefined, 2);
394466
expect(useBrowserHistoryStore.getState().byProjectKey).toEqual({});
395467
useBrowserHistoryStore.getState().registerThreadProject(threadRef, "proj-a");
396468
expect(useBrowserHistoryStore.getState().byProjectKey["proj-a"]?.map((e) => e.url)).toEqual([
@@ -408,8 +480,8 @@ describe("pendingVisitsByThreadKey", () => {
408480
threadId: ThreadId.make("thread-2"),
409481
};
410482
useBrowserHistoryStore.getState().registerThreadProject(otherThreadRef, "proj-a");
411-
recordVisitForThread(otherThreadRef, "http://newer.test/", 2000);
412-
recordVisitForThread(threadRef, "http://older.test/", 1000);
483+
recordVisitForThread(otherThreadRef, "http://newer.test/", undefined, 2000);
484+
recordVisitForThread(threadRef, "http://older.test/", undefined, 1000);
413485
useBrowserHistoryStore.getState().registerThreadProject(threadRef, "proj-a");
414486

415487
const entries = useBrowserHistoryStore.getState().byProjectKey["proj-a"];
@@ -422,7 +494,7 @@ describe("titles before registration", () => {
422494
beforeEach(resetStores);
423495

424496
it("applies a settled page's title once the matching visit drains", () => {
425-
recordVisitForThread(threadRef, "http://a.test/", 1);
497+
recordVisitForThread(threadRef, "http://a.test/", undefined, 1);
426498
settle("http://a.test/", "My App");
427499
expect(useBrowserHistoryStore.getState().byProjectKey).toEqual({});
428500

@@ -434,10 +506,10 @@ describe("titles before registration", () => {
434506

435507
it("keeps another thread's title when a queued visit to the same url drains", () => {
436508
const otherThreadRef = { ...threadRef, threadId: ThreadId.make("thread-2") };
437-
recordVisitForThread(threadRef, "http://a.test/", 1);
509+
recordVisitForThread(threadRef, "http://a.test/", undefined, 1);
438510
settle("http://a.test/", "Old", "tab_a", threadRef);
439511
useBrowserHistoryStore.getState().registerThreadProject(otherThreadRef, "proj-a");
440-
recordVisitForThread(otherThreadRef, "http://a.test/", 2);
512+
recordVisitForThread(otherThreadRef, "http://a.test/", undefined, 2);
441513
settle("http://a.test/", "New", "tab_a", otherThreadRef);
442514

443515
useBrowserHistoryStore.getState().registerThreadProject(threadRef, "proj-a");

‎apps/web/src/browserHistoryStore.ts‎

Lines changed: 20 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -3,11 +3,12 @@ import {
33
scopedThreadKey,
44
scopeProjectRef,
55
} from "@t3tools/client-runtime/environment";
6-
import type {
7-
EnvironmentId,
8-
PreviewSessionSnapshot,
9-
ScopedProjectRef,
10-
ScopedThreadRef,
6+
import {
7+
INCOGNITO_BROWSER_PROFILE_ID,
8+
type EnvironmentId,
9+
type PreviewSessionSnapshot,
10+
type ScopedProjectRef,
11+
type ScopedThreadRef,
1112
} from "@t3tools/contracts";
1213
import { create } from "zustand";
1314
import { createJSONStorage, persist } from "zustand/middleware";
@@ -398,7 +399,13 @@ function resolveThreadProjectKey(ref: ScopedThreadRef): string | undefined {
398399
return projectKey;
399400
}
400401

401-
export function recordVisitForThread(ref: ScopedThreadRef, url: string, at?: number): void {
402+
export function recordVisitForThread(
403+
ref: ScopedThreadRef,
404+
url: string,
405+
profileId?: string,
406+
at?: number,
407+
): void {
408+
if (profileId === INCOGNITO_BROWSER_PROFILE_ID) return;
402409
const threadKey = scopedThreadKey(ref);
403410
const projectKey = resolveThreadProjectKey(ref);
404411
const state = useBrowserHistoryStore.getState();
@@ -468,7 +475,13 @@ function recordPreviewTitles(
468475
);
469476
for (const session of sessions) {
470477
const status = session.navStatus;
471-
if (status._tag !== "Success" || !status.title || !include(session, status.url)) continue;
478+
if (
479+
session.profileId === INCOGNITO_BROWSER_PROFILE_ID ||
480+
status._tag !== "Success" ||
481+
!status.title ||
482+
!include(session, status.url)
483+
)
484+
continue;
472485
state.setTitleForUrl(projectKey, status.url, status.title, environmentHostname);
473486
}
474487
}

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

Lines changed: 10 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -230,15 +230,15 @@ export function PreviewView({
230230

231231
const navigateToResolvedUrl = async (resolvedUrl: string) => {
232232
if (isServerTab && serverSurfaceRef.current) {
233-
if (serverInputDisabled) return false;
233+
if (serverInputDisabled) return null;
234234
serverSurfaceRef.current.navigate(resolvedUrl);
235235
rememberPreviewUrl(threadRef, resolvedUrl);
236-
return true;
236+
return snapshot;
237237
}
238238
if (runtimeTabId && previewBridge) {
239239
await previewBridge.navigate(runtimeTabId, resolvedUrl);
240240
rememberPreviewUrl(threadRef, resolvedUrl);
241-
return true;
241+
return snapshot;
242242
}
243243
const result = await openPreviewSession({ openPreview: open, threadRef, url: resolvedUrl });
244244
if (result._tag === "Failure" && !isAtomCommandInterrupted(result)) {
@@ -251,14 +251,15 @@ export function PreviewView({
251251
});
252252
}
253253
}
254-
return result._tag === "Success";
254+
return result._tag === "Success" ? result.value : null;
255255
};
256256

257257
const handleSubmitUrl = async (next: string) => {
258258
try {
259259
const resolved = resolveAddressBarInput(next, resolveSearchUrlTemplate(getClientSettings()));
260-
if (await navigateToResolvedUrl(resolved)) {
261-
recordVisitForThread(threadRef, resolved);
260+
const navigated = await navigateToResolvedUrl(resolved);
261+
if (navigated) {
262+
recordVisitForThread(threadRef, resolved, navigated.profileId);
262263
}
263264
} catch (error) {
264265
toastManager.add({
@@ -279,8 +280,9 @@ export function PreviewView({
279280
isServerTab || !previewBridge
280281
? normalizePreviewUrl(next)
281282
: resolveDiscoveredServerUrl(threadRef.environmentId, next);
282-
if (await navigateToResolvedUrl(resolved)) {
283-
recordVisitForThread(threadRef, next);
283+
const navigated = await navigateToResolvedUrl(resolved);
284+
if (navigated) {
285+
recordVisitForThread(threadRef, next, navigated.profileId);
284286
}
285287
} catch (error) {
286288
toastManager.add({

0 commit comments

Comments
 (0)