🐛 stop shell notifiers from blanking the whole page on refetch
Browse files at this commit2114375e9b16bc60dc6da9675a0625185cdb58cdParent: 189c888- fix
- 🐛 stop shell notifiers from blanking the whole page on refetch
2 changed files +22 -12
src/components/layout/notification-center.tsxmodified+15 -9
| @@ -31,7 +31,12 @@ export function NotificationCenter() { | |||
| 31 | const [open, setOpen] = createSignal(false); | 31 | const [open, setOpen] = createSignal(false); |
| 32 | const [dismissedIds, setDismissedIds] = createSignal<Set<string>>(getDismissedNotificationIds()); | 32 | const [dismissedIds, setDismissedIds] = createSignal<Set<string>>(getDismissedNotificationIds()); |
| 33 | 33 | ||
| 34 | - // Fetch data sources | 34 | + // Fetch data sources. `initialValue` is required: the unread badge reads |
| 35 | + // these via `unreadCount()` OUTSIDE the popover's <Suspense>, so a bare | ||
| 36 | + // `resource()` would re-suspend on every 60s `refreshAll()` refetch and — since | ||
| 37 | + // this component sits beside <Outlet> in AppShell — blank the whole page for | ||
| 38 | + // the fetch duration. A seeded value keeps `resource()` non-suspending on | ||
| 39 | + // refetch (matches RightNav). | ||
| 35 | const [messagesRes, { refetch: refetchMessages }] = createResource( | 40 | const [messagesRes, { refetch: refetchMessages }] = createResource( |
| 36 | async () => { | 41 | async () => { |
| 37 | try { | 42 | try { |
| @@ -39,7 +44,8 @@ export function NotificationCenter() { | |||
| 39 | } catch { | 44 | } catch { |
| 40 | return { items: [], total: 0 }; | 45 | return { items: [], total: 0 }; |
| 41 | } | 46 | } |
| 42 | - } | 47 | + }, |
| 48 | + { initialValue: { items: [], total: 0 } } | ||
| 43 | ); | 49 | ); |
| 44 | 50 | ||
| 45 | const [eventsRes, { refetch: refetchEvents }] = createResource(async () => { | 51 | const [eventsRes, { refetch: refetchEvents }] = createResource(async () => { |
| @@ -48,7 +54,7 @@ export function NotificationCenter() { | |||
| 48 | } catch { | 54 | } catch { |
| 49 | return { items: [], total: 0 }; | 55 | return { items: [], total: 0 }; |
| 50 | } | 56 | } |
| 51 | - }); | 57 | + }, { initialValue: { items: [], total: 0 } }); |
| 52 | 58 | ||
| 53 | const [examsRes, { refetch: refetchExams }] = createResource(async () => { | 59 | const [examsRes, { refetch: refetchExams }] = createResource(async () => { |
| 54 | try { | 60 | try { |
| @@ -56,7 +62,7 @@ export function NotificationCenter() { | |||
| 56 | } catch { | 62 | } catch { |
| 57 | return { items: [], total: 0 }; | 63 | return { items: [], total: 0 }; |
| 58 | } | 64 | } |
| 59 | - }); | 65 | + }, { initialValue: { items: [], total: 0 } }); |
| 60 | 66 | ||
| 61 | const [homeworkRes, { refetch: refetchHomework }] = createResource(async () => { | 67 | const [homeworkRes, { refetch: refetchHomework }] = createResource(async () => { |
| 62 | try { | 68 | try { |
| @@ -64,7 +70,7 @@ export function NotificationCenter() { | |||
| 64 | } catch { | 70 | } catch { |
| 65 | return { items: [], total: 0 }; | 71 | return { items: [], total: 0 }; |
| 66 | } | 72 | } |
| 67 | - }); | 73 | + }, { initialValue: { items: [], total: 0 } }); |
| 68 | 74 | ||
| 69 | // Revalidate every source so an item deleted on another page stops | 75 | // Revalidate every source so an item deleted on another page stops |
| 70 | // notifying: on the periodic clock tick (badge self-heals) and whenever | 76 | // notifying: on the periodic clock tick (badge self-heals) and whenever |
| @@ -96,7 +102,7 @@ export function NotificationCenter() { | |||
| 96 | const list: NotificationItem[] = []; | 102 | const list: NotificationItem[] = []; |
| 97 | 103 | ||
| 98 | // 1. Unread Messages | 104 | // 1. Unread Messages |
| 99 | - const msgs = messagesRes()?.items ?? []; | 105 | + const msgs = messagesRes.latest?.items ?? []; |
| 100 | for (const m of msgs) { | 106 | for (const m of msgs) { |
| 101 | list.push({ | 107 | list.push({ |
| 102 | id: `msg_${m.id}`, | 108 | id: `msg_${m.id}`, |
| @@ -109,7 +115,7 @@ export function NotificationCenter() { | |||
| 109 | } | 115 | } |
| 110 | 116 | ||
| 111 | // 2. Events starting today or upcoming | 117 | // 2. Events starting today or upcoming |
| 112 | - const evts = eventsRes()?.items ?? []; | 118 | + const evts = eventsRes.latest?.items ?? []; |
| 113 | for (const e of evts) { | 119 | for (const e of evts) { |
| 114 | if (!e.starts_at) continue; | 120 | if (!e.starts_at) continue; |
| 115 | const t = new Date(e.starts_at).getTime(); | 121 | const t = new Date(e.starts_at).getTime(); |
| @@ -133,7 +139,7 @@ export function NotificationCenter() { | |||
| 133 | } | 139 | } |
| 134 | 140 | ||
| 135 | // 3. Exams starting today or upcoming | 141 | // 3. Exams starting today or upcoming |
| 136 | - const exms = examsRes()?.items ?? []; | 142 | + const exms = examsRes.latest?.items ?? []; |
| 137 | for (const ex of exms) { | 143 | for (const ex of exms) { |
| 138 | if (!ex.starts_at || ex.draft) continue; | 144 | if (!ex.starts_at || ex.draft) continue; |
| 139 | const t = new Date(ex.starts_at).getTime(); | 145 | const t = new Date(ex.starts_at).getTime(); |
| @@ -157,7 +163,7 @@ export function NotificationCenter() { | |||
| 157 | } | 163 | } |
| 158 | 164 | ||
| 159 | // 4. Homework due upcoming | 165 | // 4. Homework due upcoming |
| 160 | - const hws = homeworkRes()?.items ?? []; | 166 | + const hws = homeworkRes.latest?.items ?? []; |
| 161 | for (const hw of hws) { | 167 | for (const hw of hws) { |
| 162 | if (!hw.due_at) continue; | 168 | if (!hw.due_at) continue; |
| 163 | if (hw.due_at >= nowMs()) { | 169 | if (hw.due_at >= nowMs()) { |
src/components/layout/right-nav.tsxmodified+7 -3
| @@ -91,7 +91,11 @@ export function RightNav() { | |||
| 91 | }; | 91 | }; |
| 92 | 92 | ||
| 93 | // Computed message data | 93 | // Computed message data |
| 94 | - const allMessages = () => messagesRes().items; | 94 | + // `.latest`, not `messagesRes()`: this feeds the always-rendered unread badge, |
| 95 | + // which is outside any <Suspense>. A bare read re-suspends on every 60s refetch | ||
| 96 | + // and — since RightNav sits beside <Outlet> in AppShell — blanks the whole page | ||
| 97 | + // for the fetch duration. `.latest` keeps the last value without suspending. | ||
| 98 | + const allMessages = () => messagesRes.latest.items; | ||
| 95 | const unreadCount = createMemo(() => allMessages().filter((m: Message) => !m.read).length); | 99 | const unreadCount = createMemo(() => allMessages().filter((m: Message) => !m.read).length); |
| 96 | 100 | ||
| 97 | const filteredMessages = createMemo(() => { | 101 | const filteredMessages = createMemo(() => { |
| @@ -127,11 +131,11 @@ export function RightNav() { | |||
| 127 | }; | 131 | }; |
| 128 | 132 | ||
| 129 | const activeEvents = createMemo(() => { | 133 | const activeEvents = createMemo(() => { |
| 130 | - return eventsRes().filter((e: Event) => notEnded(e.starts_at, e.ends_at)); | 134 | + return eventsRes.latest.filter((e: Event) => notEnded(e.starts_at, e.ends_at)); |
| 131 | }); | 135 | }); |
| 132 | 136 | ||
| 133 | const activeExams = createMemo(() => { | 137 | const activeExams = createMemo(() => { |
| 134 | - return examsRes().filter((e: Exam) => !e.draft && notEnded(e.starts_at, e.ends_at)); | 138 | + return examsRes.latest.filter((e: Exam) => !e.draft && notEnded(e.starts_at, e.ends_at)); |
| 135 | }); | 139 | }); |
| 136 | 140 | ||
| 137 | const hasTodayEvents = createMemo(() => activeEvents().length > 0); | 141 | const hasTodayEvents = createMemo(() => activeEvents().length > 0); |