forge
Explore
Log in

Don't you dare go Hollow

🐛 stop shell notifiers from blanking the whole page on refetch

Browse files at this commit

2114375e9b16bc60dc6da9675a0625185cdb58cdAhmet Kaan GümüşParent: 189c888
  • fix
    • 🐛 stop shell notifiers from blanking the whole page on refetch
Show full message
fix: 🐛 stop shell notifiers from blanking the whole page on refetch
- NotificationCenter and RightNav sit beside <Outlet> in AppShell and feed
  always-rendered unread/today badges from createResource reads
- those badges read the resources OUTSIDE any <Suspense>, so a bare resource()
  re-suspends on every 60s refreshAll() refetch (initialValue does not prevent
  this) and blanks the entire page for the whole fetch duration — a visible
  multi-second reload/blank on a real backend, recurring on the clock tick,
  panel opens, and HMR remounts
- read resource.latest in the badge computeds: returns the last value without
  triggering Suspense, so refetch no longer suspends the page
- seed NotificationCenter's four resources with initialValue to match RightNav
src/components/layout/notification-center.tsxmodified+15 -9
@@ -31,7 +31,12 @@ export function NotificationCenter() {
3131 const [open, setOpen] = createSignal(false);
3232 const [dismissedIds, setDismissedIds] = createSignal<Set<string>>(getDismissedNotificationIds());
3333
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).
3540 const [messagesRes, { refetch: refetchMessages }] = createResource(
3641 async () => {
3742 try {
@@ -39,7 +44,8 @@ export function NotificationCenter() {
3944 } catch {
4045 return { items: [], total: 0 };
4146 }
42- }
47+ },
48+ { initialValue: { items: [], total: 0 } }
4349 );
4450
4551 const [eventsRes, { refetch: refetchEvents }] = createResource(async () => {
@@ -48,7 +54,7 @@ export function NotificationCenter() {
4854 } catch {
4955 return { items: [], total: 0 };
5056 }
51- });
57+ }, { initialValue: { items: [], total: 0 } });
5258
5359 const [examsRes, { refetch: refetchExams }] = createResource(async () => {
5460 try {
@@ -56,7 +62,7 @@ export function NotificationCenter() {
5662 } catch {
5763 return { items: [], total: 0 };
5864 }
59- });
65+ }, { initialValue: { items: [], total: 0 } });
6066
6167 const [homeworkRes, { refetch: refetchHomework }] = createResource(async () => {
6268 try {
@@ -64,7 +70,7 @@ export function NotificationCenter() {
6470 } catch {
6571 return { items: [], total: 0 };
6672 }
67- });
73+ }, { initialValue: { items: [], total: 0 } });
6874
6975 // Revalidate every source so an item deleted on another page stops
7076 // notifying: on the periodic clock tick (badge self-heals) and whenever
@@ -96,7 +102,7 @@ export function NotificationCenter() {
96102 const list: NotificationItem[] = [];
97103
98104 // 1. Unread Messages
99- const msgs = messagesRes()?.items ?? [];
105+ const msgs = messagesRes.latest?.items ?? [];
100106 for (const m of msgs) {
101107 list.push({
102108 id: `msg_${m.id}`,
@@ -109,7 +115,7 @@ export function NotificationCenter() {
109115 }
110116
111117 // 2. Events starting today or upcoming
112- const evts = eventsRes()?.items ?? [];
118+ const evts = eventsRes.latest?.items ?? [];
113119 for (const e of evts) {
114120 if (!e.starts_at) continue;
115121 const t = new Date(e.starts_at).getTime();
@@ -133,7 +139,7 @@ export function NotificationCenter() {
133139 }
134140
135141 // 3. Exams starting today or upcoming
136- const exms = examsRes()?.items ?? [];
142+ const exms = examsRes.latest?.items ?? [];
137143 for (const ex of exms) {
138144 if (!ex.starts_at || ex.draft) continue;
139145 const t = new Date(ex.starts_at).getTime();
@@ -157,7 +163,7 @@ export function NotificationCenter() {
157163 }
158164
159165 // 4. Homework due upcoming
160- const hws = homeworkRes()?.items ?? [];
166+ const hws = homeworkRes.latest?.items ?? [];
161167 for (const hw of hws) {
162168 if (!hw.due_at) continue;
163169 if (hw.due_at >= nowMs()) {
src/components/layout/right-nav.tsxmodified+7 -3
@@ -91,7 +91,11 @@ export function RightNav() {
9191 };
9292
9393 // 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;
9599 const unreadCount = createMemo(() => allMessages().filter((m: Message) => !m.read).length);
96100
97101 const filteredMessages = createMemo(() => {
@@ -127,11 +131,11 @@ export function RightNav() {
127131 };
128132
129133 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));
131135 });
132136
133137 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));
135139 });
136140
137141 const hasTodayEvents = createMemo(() => activeEvents().length > 0);