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

Function recordRecentPage

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

Source from the content-addressed store, hash-verified

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

Callers 1

captureFunction · 0.90

Calls 1

getRecentPagesFunction · 0.85

Tested by

no test coverage detected