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