Skip to content

Commit 487681d

Browse files
committed
fix(web): avoid redundant browser history persistence
1 parent 3116e63 commit 487681d

7 files changed

Lines changed: 107 additions & 124 deletions

File tree

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

Lines changed: 22 additions & 41 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
import { beforeEach, describe, expect, it, vi } from "vite-plus/test";
1+
import { afterEach, beforeEach, describe, expect, it, vi } from "vite-plus/test";
22

33
import { EnvironmentId, ThreadId } from "@t3tools/contracts";
44

@@ -30,6 +30,13 @@ function entry(overrides: Partial<BrowserHistoryEntry> = {}): BrowserHistoryEntr
3030
}
3131

3232
beforeEach(() => readPreparedConnection.mockReturnValue(null));
33+
afterEach(() => vi.restoreAllMocks());
34+
35+
function spyOnPersistWrites() {
36+
const storage = useBrowserHistoryStore.persist.getOptions().storage;
37+
if (!storage) throw new Error("Browser history persistence storage is unavailable.");
38+
return vi.spyOn(storage, "setItem");
39+
}
3340

3441
describe("normalizeHistoryUrl", () => {
3542
it("normalizes bare loopback hosts to http and keeps path/query", () => {
@@ -81,7 +88,6 @@ describe("upsertHistoryEntry", () => {
8188
const next = upsertHistoryEntry(full, "http://new.test/", 9999);
8289
expect(next).toHaveLength(BROWSER_HISTORY_MAX_ENTRIES_PER_PROJECT);
8390
expect(next[0]?.url).toBe("http://new.test/");
84-
// Prepending the new head pushes the LAST fixture entry off the end.
8591
const lastPort = 3000 + BROWSER_HISTORY_MAX_ENTRIES_PER_PROJECT - 1;
8692
expect(next.some((e) => e.url === `http://localhost:${lastPort}/`)).toBe(false);
8793
expect(next.some((e) => e.url === "http://localhost:3000/")).toBe(true);
@@ -220,17 +226,19 @@ describe("useBrowserHistoryStore", () => {
220226
]);
221227
});
222228

223-
it("ignores invalid urls whether queued pending or recorded post-registration", () => {
224-
recordVisitForThread(threadRef, "ftp://a.test/", 1);
229+
it("does not persist when a thread is already registered to the same project", () => {
225230
useBrowserHistoryStore.getState().registerThreadProject(threadRef, "proj-a");
226-
recordVisitForThread(threadRef, "ftp://a.test/", 2);
227-
expect(useBrowserHistoryStore.getState().byProjectKey).toEqual({});
231+
const persist = spyOnPersistWrites();
232+
233+
useBrowserHistoryStore.getState().registerThreadProject(threadRef, "proj-a");
234+
235+
expect(persist).not.toHaveBeenCalled();
228236
});
229237

230-
it("unregisters a thread when project key is null", () => {
238+
it("ignores invalid urls whether queued pending or recorded post-registration", () => {
239+
recordVisitForThread(threadRef, "ftp://a.test/", 1);
231240
useBrowserHistoryStore.getState().registerThreadProject(threadRef, "proj-a");
232-
useBrowserHistoryStore.getState().registerThreadProject(threadRef, null);
233-
recordVisitForThread(threadRef, "http://a.test/", 1);
241+
recordVisitForThread(threadRef, "ftp://a.test/", 2);
234242
expect(useBrowserHistoryStore.getState().byProjectKey).toEqual({});
235243
});
236244

@@ -243,13 +251,17 @@ describe("useBrowserHistoryStore", () => {
243251
expect(useBrowserHistoryStore.getState().byProjectKey["proj-a"]?.[0]?.title).toBe("My App");
244252
});
245253

246-
it("skips the write when the title is already set", () => {
254+
it("does not persist when the title is already set", () => {
247255
useBrowserHistoryStore.getState().registerThreadProject(threadRef, "proj-a");
248256
recordVisitForThread(threadRef, "http://a.test/", 1);
249257
setTitleForThreadUrl(threadRef, "http://a.test/", "My App");
258+
const persist = spyOnPersistWrites();
250259
const byProjectKey = useBrowserHistoryStore.getState().byProjectKey;
260+
251261
setTitleForThreadUrl(threadRef, "http://a.test/", "My App");
262+
252263
expect(useBrowserHistoryStore.getState().byProjectKey).toBe(byProjectKey);
264+
expect(persist).not.toHaveBeenCalled();
253265
});
254266

255267
it("sets a title against a settled url that differs from the stored one only by a trailing slash", () => {
@@ -353,27 +365,13 @@ describe("pendingVisitsByThreadKey", () => {
353365
expect(useBrowserHistoryStore.getState().pendingVisitsByThreadKey).toEqual({});
354366
});
355367

356-
it("preserves pending visits through a null registration and drains them later", () => {
357-
recordVisitForThread(threadRef, "http://a.test/", 1);
358-
useBrowserHistoryStore.getState().registerThreadProject(threadRef, null);
359-
expect(Object.values(useBrowserHistoryStore.getState().pendingVisitsByThreadKey)).toEqual([
360-
[{ url: "http://a.test/", at: 1, environmentHostname: null }],
361-
]);
362-
useBrowserHistoryStore.getState().registerThreadProject(threadRef, "proj-a");
363-
expect(useBrowserHistoryStore.getState().byProjectKey["proj-a"]).toEqual([
364-
{ url: "http://a.test/", lastVisitedAt: 1 },
365-
]);
366-
expect(useBrowserHistoryStore.getState().pendingVisitsByThreadKey).toEqual({});
367-
});
368-
369368
it("caps the per-thread pending list at 10, dropping the oldest", () => {
370369
for (let i = 0; i < 12; i++) {
371370
recordVisitForThread(threadRef, `http://a.test/${i}`, i);
372371
}
373372
useBrowserHistoryStore.getState().registerThreadProject(threadRef, "proj-a");
374373
const urls = useBrowserHistoryStore.getState().byProjectKey["proj-a"]?.map((e) => e.url);
375374
expect(urls).toHaveLength(10);
376-
// Oldest two (index 0, 1) were dropped; newest (index 11) drained last so it's MRU.
377375
expect(urls).not.toContain("http://a.test/0");
378376
expect(urls).not.toContain("http://a.test/1");
379377
expect(urls?.[0]).toBe("http://a.test/11");
@@ -384,10 +382,8 @@ describe("pendingVisitsByThreadKey", () => {
384382
environmentId: EnvironmentId.make("env-1"),
385383
threadId: ThreadId.make("thread-2"),
386384
};
387-
// Another thread in the same project records a visit live...
388385
useBrowserHistoryStore.getState().registerThreadProject(otherThreadRef, "proj-a");
389386
recordVisitForThread(otherThreadRef, "http://newer.test/", 2000);
390-
// ...while this thread's older visit was queued before it registered.
391387
recordVisitForThread(threadRef, "http://older.test/", 1000);
392388
useBrowserHistoryStore.getState().registerThreadProject(threadRef, "proj-a");
393389

@@ -415,21 +411,6 @@ describe("pendingTitlesByThreadKey", () => {
415411
expect(useBrowserHistoryStore.getState().pendingTitlesByThreadKey).toEqual({});
416412
});
417413

418-
it("preserves pending titles through a null registration and applies them later", () => {
419-
recordVisitForThread(threadRef, "http://a.test/", 1);
420-
setTitleForThreadUrl(threadRef, "http://a.test/", "My App");
421-
useBrowserHistoryStore.getState().registerThreadProject(threadRef, null);
422-
expect(Object.values(useBrowserHistoryStore.getState().pendingTitlesByThreadKey)).toEqual([
423-
[{ url: "http://a.test/", title: "My App", environmentHostname: undefined }],
424-
]);
425-
useBrowserHistoryStore.getState().registerThreadProject(threadRef, "proj-a");
426-
expect(useBrowserHistoryStore.getState().byProjectKey["proj-a"]?.[0]).toMatchObject({
427-
url: "http://a.test/",
428-
title: "My App",
429-
});
430-
expect(useBrowserHistoryStore.getState().pendingTitlesByThreadKey).toEqual({});
431-
});
432-
433414
it("preserves environment host matching while a title is pending", () => {
434415
recordVisitForThread(threadRef, "http://localhost:5173/app", 1);
435416
setTitleForThreadUrl(threadRef, "http://192.168.64.2:5173/app", "Local App", "192.168.64.2");

‎apps/web/src/browserHistoryStore.ts‎

Lines changed: 58 additions & 68 deletions
Original file line numberDiff line numberDiff line change
@@ -164,7 +164,7 @@ interface BrowserHistoryStoreState {
164164
environmentHostname?: string | null,
165165
) => void;
166166
removeUrl: (projectKey: string, url: string) => void;
167-
registerThreadProject: (ref: ScopedThreadRef, projectKey: string | null) => void;
167+
registerThreadProject: (ref: ScopedThreadRef, projectKey: string) => void;
168168
}
169169

170170
function addPendingByThread<T>(
@@ -190,10 +190,10 @@ export const useBrowserHistoryStore = create<BrowserHistoryStoreState>()(
190190
projectKeyByThreadKey: {},
191191
pendingVisitsByThreadKey: {},
192192
pendingTitlesByThreadKey: {},
193-
recordVisit: (projectKey, url, at, options) =>
193+
recordVisit: (projectKey, url, at, options) => {
194+
const normalized = normalizeHistoryUrl(url);
195+
if (!normalized) return;
194196
set((state) => {
195-
const normalized = normalizeHistoryUrl(url);
196-
if (!normalized) return state;
197197
return {
198198
byProjectKey: evictExcessProjects({
199199
...state.byProjectKey,
@@ -205,73 +205,63 @@ export const useBrowserHistoryStore = create<BrowserHistoryStoreState>()(
205205
),
206206
}),
207207
};
208-
}),
209-
setTitleForUrl: (projectKey, url, title, environmentHostname) =>
210-
set((state) => {
211-
const normalized = normalizeHistoryUrl(url);
212-
const entries = state.byProjectKey[projectKey];
213-
const trimmed = title.trim().slice(0, BROWSER_HISTORY_MAX_TITLE_LENGTH);
214-
if (!normalized || !entries || trimmed.length === 0) return state;
215-
const key = titleLookupKey(normalized, environmentHostname);
216-
const index = entries.findIndex(
217-
(candidate) => titleLookupKey(candidate.url, environmentHostname) === key,
218-
);
219-
if (index === -1) return state;
220-
// Skip the write when nothing changed so unrelated re-renders don't
221-
// trigger a fresh persist of the whole history blob.
222-
if (entries[index]?.title === trimmed) return state;
223-
return {
224-
byProjectKey: {
225-
...state.byProjectKey,
226-
[projectKey]: entries.map((candidate, candidateIndex) =>
227-
candidateIndex === index ? { ...candidate, title: trimmed } : candidate,
228-
),
229-
},
230-
};
231-
}),
232-
removeUrl: (projectKey, url) =>
233-
set((state) => {
234-
const normalized = normalizeHistoryUrl(url);
235-
const entries = state.byProjectKey[projectKey];
236-
if (!normalized || !entries) return state;
237-
const next = entries.filter((candidate) => candidate.url !== normalized);
238-
if (next.length === entries.length) return state;
239-
if (next.length === 0) {
240-
const { [projectKey]: _removed, ...rest } = state.byProjectKey;
241-
return { byProjectKey: rest };
242-
}
243-
return { byProjectKey: { ...state.byProjectKey, [projectKey]: next } };
244-
}),
208+
});
209+
},
210+
setTitleForUrl: (projectKey, url, title, environmentHostname) => {
211+
const normalized = normalizeHistoryUrl(url);
212+
const state = get();
213+
const entries = state.byProjectKey[projectKey];
214+
const trimmed = title.trim().slice(0, BROWSER_HISTORY_MAX_TITLE_LENGTH);
215+
if (!normalized || !entries || trimmed.length === 0) return;
216+
const key = titleLookupKey(normalized, environmentHostname);
217+
const index = entries.findIndex(
218+
(candidate) => titleLookupKey(candidate.url, environmentHostname) === key,
219+
);
220+
if (index === -1 || entries[index]?.title === trimmed) return;
221+
set({
222+
byProjectKey: {
223+
...state.byProjectKey,
224+
[projectKey]: entries.map((candidate, candidateIndex) =>
225+
candidateIndex === index ? { ...candidate, title: trimmed } : candidate,
226+
),
227+
},
228+
});
229+
},
230+
removeUrl: (projectKey, url) => {
231+
const normalized = normalizeHistoryUrl(url);
232+
const state = get();
233+
const entries = state.byProjectKey[projectKey];
234+
if (!normalized || !entries) return;
235+
const next = entries.filter((candidate) => candidate.url !== normalized);
236+
if (next.length === entries.length) return;
237+
if (next.length === 0) {
238+
const { [projectKey]: _removed, ...rest } = state.byProjectKey;
239+
set({ byProjectKey: rest });
240+
return;
241+
}
242+
set({ byProjectKey: { ...state.byProjectKey, [projectKey]: next } });
243+
},
245244
registerThreadProject: (ref, projectKey) => {
246245
const threadKey = scopedThreadKey(ref);
247-
let pendingVisits: PendingVisit[] | undefined;
248-
let pendingTitles: PendingTitle[] | undefined;
249-
set((state) => {
250-
if (projectKey === null) {
251-
if (!(threadKey in state.projectKeyByThreadKey)) return state;
252-
const { [threadKey]: _removed, ...rest } = state.projectKeyByThreadKey;
253-
return { projectKeyByThreadKey: rest };
254-
}
255-
pendingVisits = state.pendingVisitsByThreadKey[threadKey];
256-
pendingTitles = state.pendingTitlesByThreadKey[threadKey];
257-
if (
258-
state.projectKeyByThreadKey[threadKey] === projectKey &&
259-
!pendingVisits &&
260-
!pendingTitles
261-
) {
262-
return state;
263-
}
264-
const nextPendingVisits = { ...state.pendingVisitsByThreadKey };
265-
const nextPendingTitles = { ...state.pendingTitlesByThreadKey };
266-
delete nextPendingVisits[threadKey];
267-
delete nextPendingTitles[threadKey];
268-
return {
269-
projectKeyByThreadKey: { ...state.projectKeyByThreadKey, [threadKey]: projectKey },
270-
pendingVisitsByThreadKey: nextPendingVisits,
271-
pendingTitlesByThreadKey: nextPendingTitles,
272-
};
246+
const state = get();
247+
const pendingVisits = state.pendingVisitsByThreadKey[threadKey];
248+
const pendingTitles = state.pendingTitlesByThreadKey[threadKey];
249+
if (
250+
state.projectKeyByThreadKey[threadKey] === projectKey &&
251+
!pendingVisits &&
252+
!pendingTitles
253+
) {
254+
return;
255+
}
256+
const nextPendingVisits = { ...state.pendingVisitsByThreadKey };
257+
const nextPendingTitles = { ...state.pendingTitlesByThreadKey };
258+
delete nextPendingVisits[threadKey];
259+
delete nextPendingTitles[threadKey];
260+
set({
261+
projectKeyByThreadKey: { ...state.projectKeyByThreadKey, [threadKey]: projectKey },
262+
pendingVisitsByThreadKey: nextPendingVisits,
263+
pendingTitlesByThreadKey: nextPendingTitles,
273264
});
274-
if (projectKey === null) return;
275265
for (const visit of pendingVisits ?? [])
276266
get().recordVisit(projectKey, visit.url, visit.at, {
277267
insertOrdered: true,

‎apps/web/src/components/ChatView.tsx‎

Lines changed: 22 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -175,7 +175,11 @@ import { newDraftId, newMessageId, newThreadId } from "~/lib/utils";
175175
import { useBrowserHistoryStore } from "~/browserHistoryStore";
176176
import { getProviderModelCapabilities, resolveSelectableProvider } from "../providerModels";
177177
import { NO_PROVIDER_MODEL_SELECTION } from "../providerInstances";
178-
import { useClientSettings, useEnvironmentSettings } from "../hooks/useSettings";
178+
import {
179+
useClientSettings,
180+
useClientSettingsHydrated,
181+
useEnvironmentSettings,
182+
} from "../hooks/useSettings";
179183
import { useNowMinute } from "../hooks/useNowMinute";
180184
import { useNewThreadHandler } from "../hooks/useHandleNewThread";
181185
import { resolveAppModelSelectionForInstance } from "../modelSelection";
@@ -1494,6 +1498,7 @@ function ChatViewContent(props: ChatViewProps) {
14941498
const isLocalDraftThread = !isServerThread && localDraftThread !== undefined;
14951499
const canCheckoutPullRequestIntoThread = isLocalDraftThread;
14961500
const activeThreadId = activeThread?.id ?? null;
1501+
const activeThreadEnvironmentId = activeThread?.environmentId ?? null;
14971502
const runningTerminalIds = useThreadRunningTerminalIds({
14981503
environmentId: activeThread?.environmentId ?? null,
14991504
threadId: activeThreadId,
@@ -1529,8 +1534,11 @@ function ChatViewContent(props: ChatViewProps) {
15291534
return labels;
15301535
}, [activeThreadKnownSessions]);
15311536
const activeThreadRef = useMemo(
1532-
() => (activeThread ? scopeThreadRef(activeThread.environmentId, activeThread.id) : null),
1533-
[activeThread],
1537+
() =>
1538+
activeThreadEnvironmentId && activeThreadId
1539+
? scopeThreadRef(activeThreadEnvironmentId, activeThreadId)
1540+
: null,
1541+
[activeThreadEnvironmentId, activeThreadId],
15341542
);
15351543
const activeThreadKey = activeThreadRef ? scopedThreadKey(activeThreadRef) : null;
15361544
const [timelineAnchor, setTimelineAnchor] = useState<{
@@ -1655,7 +1663,8 @@ function ChatViewContent(props: ChatViewProps) {
16551663
const activeProjectKey = activeProject
16561664
? `${activeProject.environmentId}:${activeProject.workspaceRoot}`
16571665
: null;
1658-
const projectGroupingSettings = selectProjectGroupingSettings(settings);
1666+
const projectGroupingSettings = useClientSettings(selectProjectGroupingSettings);
1667+
const clientSettingsHydrated = useClientSettingsHydrated();
16591668
const [pendingFileSurfaceIdsByProject, setPendingFileSurfaceIdsByProject] = useState<
16601669
ReadonlyMap<string, ReadonlySet<string>>
16611670
>(() => new Map());
@@ -1695,7 +1704,7 @@ function ChatViewContent(props: ChatViewProps) {
16951704
const allProjects = useProjects();
16961705
const primaryEnvironmentId = primaryEnvironment?.environmentId ?? null;
16971706
useEffect(() => {
1698-
if (!activeThreadRef || !activeProject) return;
1707+
if (!clientSettingsHydrated || !activeThreadRef || !activeProject) return;
16991708
// Reuse the sidebar's grouping so history follows the project rows the user
17001709
// sees. Deriving the key from the active project alone would miss the
17011710
// identity a duplicate row borrows from its siblings.
@@ -1711,7 +1720,14 @@ function ChatViewContent(props: ChatViewProps) {
17111720
logicalKeyByPhysicalKey.get(derivePhysicalProjectKey(activeProject)) ??
17121721
deriveLogicalProjectKeyFromSettings(activeProject, projectGroupingSettings),
17131722
);
1714-
}, [activeProject, activeThreadRef, allProjects, primaryEnvironmentId, projectGroupingSettings]);
1723+
}, [
1724+
activeProject,
1725+
activeThreadRef,
1726+
allProjects,
1727+
clientSettingsHydrated,
1728+
primaryEnvironmentId,
1729+
projectGroupingSettings,
1730+
]);
17151731
const activeEnvironment =
17161732
activeThread == null ? null : (environmentById.get(activeThread.environmentId) ?? null);
17171733
const activeEnvironmentConnectionPhase = activeEnvironment?.connection.phase ?? "available";

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
import { cn } from "~/lib/utils";
22

3-
/** Browser-window thumbnail glyph for the "Local" recommendation cards. */
3+
/** Browser-window thumbnail glyph for preview recommendation cards. */
44
export function BrowserMockup({ className }: { className?: string }) {
55
return (
66
<div

‎apps/web/src/components/preview/PreviewEmptyState.test.tsx‎

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -54,15 +54,14 @@ describe("PreviewEmptyState", () => {
5454
mocks.servers = [server(5173)];
5555
const html = render([
5656
{ url: "https://myapp.test/admin#users", lastVisitedAt: Date.now(), title: "Admin" },
57-
{ url: "http://localhost:5173/", lastVisitedAt: Date.now() },
57+
{ url: "http://localhost:5173/", lastVisitedAt: Date.now(), title: "Recent Local" },
5858
]);
5959
expect(html).toContain("Recently used");
6060
expect(html).toContain("Local servers");
6161
expect(html).toContain("myapp.test/admin#users");
6262
expect(html).toContain("Admin");
63-
// 3 occurrences confirms no dedupe: the recents card contributes 2 (label
64-
// text plus the remove button's aria-label), the server card 1 more.
65-
expect(html.split("localhost:5173").length - 1).toBe(3);
63+
expect(html).toContain("Recent Local");
64+
expect(html).toContain("node");
6665
});
6766

6867
it("renders only the recents group when no servers are found", () => {

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

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -34,8 +34,6 @@ vi.mock("~/browserHistoryStore", () => ({
3434
setTitleForThreadUrl: vi.fn(),
3535
removeUrlForThread: vi.fn(),
3636
BROWSER_HISTORY_MAX_ENTRIES_PER_PROJECT: 50,
37-
// Module-level constant: an inline `() => []` returns a fresh reference per
38-
// render and defeats the memoization the real hook guarantees.
3937
useThreadRecentHistory: () => EMPTY_HISTORY,
4038
}));
4139

0 commit comments

Comments
 (0)