(entry: RecentPage)
| 95 | }; |
| 96 | |
| 97 | export 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 | }; |
no test coverage detected