(entry: RecentPage)
| 53 | }; |
| 54 | |
| 55 | export 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 | }; |
no test coverage detected