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

Function recordRecentPage

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

Source from the content-addressed store, hash-verified

95};
96
97export const recordRecentPage = (entry: RecentPage): void => {
98 if (typeof window === 'undefined' || !entry.path || !entry.title) {
99 return;
100 }
101
102 const current = getRecentPages();
103 const head = { ...entry, ...pendingMeta.get(entry.path) };
104 pendingMeta.delete(entry.path);
105 const next = [
106 head,
107 ...current.filter((page) => page.path !== entry.path),
108 ].slice(0, MAX_RECENT);
109
110 // Skip no-op updates (same head path + title) to avoid needless re-renders
111 // when an effect re-fires for the page already at the front.
112 const isNoop =
113 current.length === next.length &&
114 current.every((page, index) => page.path === next[index].path) &&
115 current[0]?.title === next[0]?.title &&
116 current[0]?.image === next[0]?.image;
117 if (isNoop) {
118 return;
119 }
120
121 persist(next);
122};

Callers 1

captureFunction · 0.90

Calls 2

getRecentPagesFunction · 0.85
persistFunction · 0.70

Tested by

no test coverage detected