@devries-cameron20 / t3code Mirror · read-only / commits / 2e18418abf
Fork 0

The best way to control Claude Code, Codex and more from any computer or phone

Mirrored from https://github.com/Camo67/t3code.git

Synced Nov 21, 21:00 UTC

fix(web): Incognito browser visits stay out of project history (#34859)

Julius Marminge committed Nov 12, 2026 at 00:00 UTC 2e18418abf6fdb394173bf5671fd341d9e43f92f
3 files changed +42 -12
apps/web/src/browserHistoryStore.test.ts
+21 -1
@@ -2,7 +2,9 @@ import { afterEach, beforeEach, describe, expect, it, vi } from "vite-plus/test"
2
3 import { scopeProjectRef } from "@t3tools/client-runtime/environment";
4 import {
5 + type BrowserProfileId,
6 EnvironmentId,
7 + INCOGNITO_BROWSER_PROFILE_ID,
8 type PreviewSessionSnapshot,
9 ProjectId,
10 ThreadId,
@@ -157,7 +159,13 @@ const threadRef = {
159
160 let settledAt = 0;
161
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?: BrowserProfileId,
168 +): void {
169 settledAt += 1;
170 const snapshot: PreviewSessionSnapshot = {
171 threadId: ref.threadId,
@@ -166,6 +174,7 @@ function settle(url: string, title: string, tabId = "tab_a", ref = threadRef): v
174 canGoBack: false,
175 canGoForward: false,
176 updatedAt: new Date(settledAt).toISOString(),
177 + ...(profileId ? { profileId } : {}),
178 };
179 applyPreviewServerSnapshot(ref, snapshot);
180 }
@@ -208,6 +217,17 @@ describe("useBrowserHistoryStore", () => {
217 expect(useBrowserHistoryStore.getState().byProjectKey["proj-a"]?.[0]?.title).toBe("New");
218 });
219
220 + it("never titles history from an Incognito page, whichever settles first", () => {
221 + useBrowserHistoryStore.getState().registerThreadProject(threadRef, "proj-a");
222 + settle("http://a.test/", "Private A", "tab_incognito", threadRef, INCOGNITO_BROWSER_PROFILE_ID);
223 + recordVisitForThread(threadRef, "http://a.test/", 1);
224 + recordVisitForThread(threadRef, "http://b.test/", 2);
225 + settle("http://b.test/", "Private B", "tab_incognito", threadRef, INCOGNITO_BROWSER_PROFILE_ID);
226 + expect(
227 + useBrowserHistoryStore.getState().byProjectKey["proj-a"]?.map((entry) => entry.title),
228 + ).toEqual([undefined, undefined]);
229 + });
230 +
231 it("keeps another thread's newer title when an unrelated tab settles", () => {
232 const otherThreadRef = { ...threadRef, threadId: ThreadId.make("thread-2") };
233 const store = useBrowserHistoryStore.getState();
apps/web/src/browserHistoryStore.ts
+7 -5
@@ -3,11 +3,12 @@ import {
3 scopedThreadKey,
4 scopeProjectRef,
5 } from "@t3tools/client-runtime/environment";
6 -import type {
7 - EnvironmentId,
8 - PreviewSessionSnapshot,
9 - ScopedProjectRef,
10 - ScopedThreadRef,
6 +import {
7 + type EnvironmentId,
8 + INCOGNITO_BROWSER_PROFILE_ID,
9 + type PreviewSessionSnapshot,
10 + type ScopedProjectRef,
11 + type ScopedThreadRef,
12 } from "@t3tools/contracts";
13 import { create } from "zustand";
14 import { createJSONStorage, persist } from "zustand/middleware";
@@ -468,6 +469,7 @@ function recordPreviewTitles(
469 );
470 for (const session of sessions) {
471 const status = session.navStatus;
472 + if (session.profileId === INCOGNITO_BROWSER_PROFILE_ID) continue;
473 if (status._tag !== "Success" || !status.title || !include(session, status.url)) continue;
474 state.setTitleForUrl(projectKey, status.url, status.title, environmentHostname);
475 }
apps/web/src/components/preview/PreviewView.tsx
+14 -6
@@ -10,6 +10,7 @@ import {
10 import {
11 AuthOrchestrationOperateScope,
12 DEFAULT_BROWSER_PROFILE_ID,
13 + INCOGNITO_BROWSER_PROFILE_ID,
14 FILL_PREVIEW_VIEWPORT,
15 type PreviewAnnotationPayload,
16 type ScopedThreadRef,
@@ -252,18 +253,19 @@ export function PreviewView({
253 runtimeTabId ? (state.byTabId[runtimeTabId]?.rect ?? null) : null,
254 );
255
256 + /** Resolves to the profile of the tab that loaded the URL, or null when nothing opened. */
257 const navigateToResolvedUrl = async (resolvedUrl: string) => {
258 if (isServerTab && serverSurfaceRef.current) {
257 - if (serverInputDisabled) return false;
259 + if (serverInputDisabled) return null;
260 serverSurfaceRef.current.navigate(resolvedUrl);
261 rememberPreviewUrl(threadRef, resolvedUrl);
260 - return true;
262 + return activeProfileId;
263 }
264 if (runtimeTabId && previewBridge) {
265 await previewBridge.navigate(runtimeTabId, resolvedUrl);
266 rememberPreviewUrl(threadRef, resolvedUrl);
267 focusPreviewPage(runtimeTabId);
266 - return true;
268 + return activeProfileId;
269 }
270 const result = await openPreviewSession({ openPreview: open, threadRef, url: resolvedUrl });
271 if (result._tag === "Failure" && !isAtomCommandInterrupted(result)) {
@@ -276,13 +278,19 @@ export function PreviewView({
278 });
279 }
280 }
279 - return result._tag === "Success";
281 + return result._tag === "Success"
282 + ? (result.value.profileId ?? DEFAULT_BROWSER_PROFILE_ID)
283 + : null;
284 };
285
286 + // Incognito visits stay out of the project's persisted history.
287 + const isHistoryProfile = (profileId: string | null) =>
288 + profileId !== null && profileId !== INCOGNITO_BROWSER_PROFILE_ID;
289 +
290 const handleSubmitUrl = async (next: string) => {
291 try {
292 const resolved = resolveAddressBarInput(next, resolveSearchUrlTemplate(getClientSettings()));
285 - if (await navigateToResolvedUrl(resolved)) {
293 + if (isHistoryProfile(await navigateToResolvedUrl(resolved))) {
294 recordVisitForThread(threadRef, resolved);
295 }
296 } catch (error) {
@@ -304,7 +312,7 @@ export function PreviewView({
312 isServerTab || !previewBridge
313 ? normalizePreviewUrl(next)
314 : resolveDiscoveredServerUrl(threadRef.environmentId, next);
307 - if (await navigateToResolvedUrl(resolved)) {
315 + if (isHistoryProfile(await navigateToResolvedUrl(resolved))) {
316 recordVisitForThread(threadRef, next);
317 }
318 } catch (error) {