| 12 | const listeners = new Set<() => void>(); |
| 13 | |
| 14 | const readStorage = (): RecentPage[] => { |
| 15 | if (typeof window === 'undefined') { |
| 16 | return []; |
| 17 | } |
| 18 | try { |
| 19 | const raw = window.localStorage.getItem(STORAGE_KEY); |
| 20 | const parsed = raw ? JSON.parse(raw) : []; |
| 21 | if (!Array.isArray(parsed)) { |
| 22 | return []; |
| 23 | } |
| 24 | return parsed.filter( |
| 25 | (item): item is RecentPage => |
| 26 | !!item && |
| 27 | typeof item.path === 'string' && |
| 28 | typeof item.title === 'string', |
| 29 | ); |
| 30 | } catch { |
| 31 | return []; |
| 32 | } |
| 33 | }; |
| 34 | |
| 35 | export const getRecentPages = (): RecentPage[] => { |
| 36 | if (cache === null) { |