MCPcopy Create free account
hub / github.com/dailydotdev/apps / recordRecentPage

Function recordRecentPage

packages/shared/src/lib/recentPages.ts:49–77  ·  view source on GitHub ↗
(entry: RecentPage)

Source from the content-addressed store, hash-verified

47};
48
49export const recordRecentPage = (entry: RecentPage): void => {
50 if (typeof window === 'undefined' || !entry.path || !entry.title) {
51 return;
52 }
53
54 const current = getRecentPages();
55 const next = [
56 entry,
57 ...current.filter((page) => page.path !== entry.path),
58 ].slice(0, MAX_RECENT);
59
60 // Skip no-op updates (same head path + title) to avoid needless re-renders
61 // when an effect re-fires for the page already at the front.
62 const isNoop =
63 current.length === next.length &&
64 current.every((page, index) => page.path === next[index].path) &&
65 current[0]?.title === next[0]?.title;
66 if (isNoop) {
67 return;
68 }
69
70 cache = next;
71 try {
72 window.localStorage.setItem(STORAGE_KEY, JSON.stringify(next));
73 } catch {
74 // ignore storage quota / privacy-mode failures
75 }
76 listeners.forEach((listener) => listener());
77};

Callers 1

captureFunction · 0.90

Calls 1

getRecentPagesFunction · 0.85

Tested by

no test coverage detected