Self-hosted, Self-Improving, Federated Everything App — dev management, agent orchestration, persistent mind, digital twin, second brain, and creative pipeline from a single dashboard over Tailscale to port the user into the OS
JavaScript ai-agentsdashboarddeveloper-toolsdigital-twinquantified-selfsecond-brainself-hostedtailscale
fix: keep calendar day and week events consistent during refreshes (#9699)
Adam Eivyca35be265f82
diff --git a/client/src/components/calendar/DayView.jsx b/client/src/components/calendar/DayView.jsxindex 0e7ec26144..a74b814132 100644--- a/client/src/components/calendar/DayView.jsx+++ b/client/src/components/calendar/DayView.jsx@@ -1,4 +1,4 @@-import { useState, useEffect, useCallback, useMemo } from 'react';+import { useState, useEffect, useMemo } from 'react';import {CalendarDays, ChevronLeft, ChevronRight, MapPin} from 'lucide-react';import * as api from '../../services/api';import socket from '../../services/socket';@@ -23,21 +23,28 @@ export default function DayView({ accounts }) {const [searchParams, updateParams] = useUrlParams();const { theme } = useThemeContext();- const fetchEvents = useCallback(async () => {- const startDate = date.toISOString();- const nextDay = new Date(date);- nextDay.setDate(nextDay.getDate() + 1);- const endDate = nextDay.toISOString();- const data = await api.getCalendarEvents({ startDate, endDate, limit: 200 }).catch(() => ({ events: [] }));- setEvents(data?.events || []);- setLoading(false);- }, [date]);-- useEffect(() => { fetchEvents(); }, [fetchEvents]);useEffect(() => {+ let active = true;+ let request = 0;+ const fetchEvents = async () => {+ const currentRequest = ++request;+ const startDate = date.toISOString();+ const nextDay = new Date(date);+ nextDay.setDate(nextDay.getDate() + 1);+ const endDate = nextDay.toISOString();+ const data = await api.getCalendarEvents({ startDate, endDate, limit: 200 }).catch(() => ({ events: [] }));+ if (!active || currentRequest !== request) return;+ setEvents(data?.events || []);+ setLoading(false);+ };+ setLoading(true);+ fetchEvents();socket.on('calendar:sync:completed', fetchEvents);- return () => socket.off('calendar:sync:completed', fetchEvents);- }, [fetchEvents]);+ return () => {+ active = false;+ socket.off('calendar:sync:completed', fetchEvents);+ };+ }, [date]);const navigate = (days) => {setDate(prev => {@@ -45,14 +52,12 @@ export default function DayView({ accounts }) {d.setDate(d.getDate() + days);return d;});- setLoading(true);};const goToday = () => {const d = new Date();d.setHours(0, 0, 0, 0);setDate(d);- setLoading(true);};const allDayEvents = useMemo(() => events.filter(e => e.isAllDay && eventOccursOnDay(e, date)), [events, date]);diff --git a/client/src/components/calendar/WeekView.jsx b/client/src/components/calendar/WeekView.jsxindex 9e7dc8a031..4dd228dc14 100644--- a/client/src/components/calendar/WeekView.jsx+++ b/client/src/components/calendar/WeekView.jsx@@ -1,4 +1,4 @@-import { useState, useEffect, useCallback, useMemo } from 'react';+import { useState, useEffect, useMemo } from 'react';import {CalendarDays, ChevronLeft, ChevronRight} from 'lucide-react';import * as api from '../../services/api';import socket from '../../services/socket';@@ -40,21 +40,28 @@ export default function WeekView({ accounts }) {const weekStartIso = weekStart.toISOString();const weekEndIso = weekEnd.toISOString();- const fetchEvents = useCallback(async () => {- const data = await api.getCalendarEvents({- startDate: weekStartIso,- endDate: weekEndIso,- limit: 200- }).catch(() => ({ events: [] }));- setEvents(data?.events || []);- setLoading(false);- }, [weekEndIso, weekStartIso]);-- useEffect(() => { fetchEvents(); }, [fetchEvents]);useEffect(() => {+ let active = true;+ let request = 0;+ const fetchEvents = async () => {+ const currentRequest = ++request;+ const data = await api.getCalendarEvents({+ startDate: weekStartIso,+ endDate: weekEndIso,+ limit: 200+ }).catch(() => ({ events: [] }));+ if (!active || currentRequest !== request) return;+ setEvents(data?.events || []);+ setLoading(false);+ };+ setLoading(true);+ fetchEvents();socket.on('calendar:sync:completed', fetchEvents);- return () => socket.off('calendar:sync:completed', fetchEvents);- }, [fetchEvents]);+ return () => {+ active = false;+ socket.off('calendar:sync:completed', fetchEvents);+ };+ }, [weekEndIso, weekStartIso]);const navigate = (weeks) => {setWeekStart(prev => {@@ -62,12 +69,10 @@ export default function WeekView({ accounts }) {d.setDate(d.getDate() + weeks * 7);return d;});- setLoading(true);};const goToday = () => {setWeekStart(getWeekStart(new Date()));- setLoading(true);};const colorMap = useMemo(() => buildSubcalendarColorMap(accounts), [accounts]);diff --git a/client/src/components/calendar/calendarEventChips.test.jsx b/client/src/components/calendar/calendarEventChips.test.jsxindex 2a72aca046..5a1b0c1758 100644--- a/client/src/components/calendar/calendarEventChips.test.jsx+++ b/client/src/components/calendar/calendarEventChips.test.jsx@@ -256,6 +256,88 @@ describe.each([});});+describe.each([+ ['DayView', DayView, 'Next day'],+ ['WeekView', WeekView, 'Next week'],+])('%s event request ordering', (_name, View, nextLabel) => {+ let requests;++ beforeEach(() => {+ vi.useFakeTimers({ toFake: ['Date'] });+ vi.setSystemTime(new Date(2026, 8, 8, 12));+ requests = [];+ api.getCalendarEvents.mockImplementation(params => new Promise(resolve => {+ requests.push({ params, resolve });+ }));+ });++ const resolveEvents = async (request, title) => {+ const start = new Date(request.params.startDate);+ start.setHours(10);+ const end = new Date(start);+ end.setHours(11);+ await act(async () => request.resolve({ events: [{+ ...TIMED, id: title, title, startTime: start.toISOString(), endTime: end.toISOString(),+ }] }));+ };++ it('keeps the new date heading and events when the previous window resolves last', async () => {+ await renderView(<View accounts={ACCOUNTS} />);+ const oldHeading = screen.getByRole('heading', { level: 2 }).textContent;+ fireEvent.click(screen.getByRole('button', { name: nextLabel }));+ expect(requests).toHaveLength(2);+ const newHeading = screen.getByRole('heading', { level: 2 }).textContent;+ expect(newHeading).not.toBe(oldHeading);++ await resolveEvents(requests[1], 'Example current event');+ expect(chipFor('Example current event')).toBeInTheDocument();+ await resolveEvents(requests[0], 'Example previous event');++ expect(screen.getByRole('heading', { level: 2 }).textContent).toBe(newHeading);+ expect(chipFor('Example current event')).toBeInTheDocument();+ expect(screen.queryByRole('button', { name: /Example previous event/ })).not.toBeInTheDocument();+ });++ it('keeps the new window loading when an obsolete request finishes first', async () => {+ await renderView(<View accounts={ACCOUNTS} />);+ fireEvent.click(screen.getByRole('button', { name: nextLabel }));+ await resolveEvents(requests[0], 'Example previous event');+ expect(screen.getByText('Loading')).toBeInTheDocument();++ await resolveEvents(requests[1], 'Example current event');+ expect(screen.queryByText('Loading')).not.toBeInTheDocument();+ expect(chipFor('Example current event')).toBeInTheDocument();+ });++ it('keeps Today usable when already showing the current window', async () => {+ await renderView(<View accounts={ACCOUNTS} />);+ await resolveEvents(requests[0], 'Example current event');+ fireEvent.click(screen.getByRole('button', { name: 'Today' }));+ if (requests.length > 1) await resolveEvents(requests[1], 'Example current event');+ expect(screen.queryByText('Loading')).not.toBeInTheDocument();+ expect(chipFor('Example current event')).toBeInTheDocument();+ });++ it('keeps the latest socket refresh and disposes its listener with pending work', async () => {+ const mounted = render(<MemoryRouter><View accounts={ACCOUNTS} /></MemoryRouter>);+ await resolveEvents(requests[0], 'Example initial event');+ const refresh = socketMock.on.mock.calls.find(([event]) => event === 'calendar:sync:completed')[1];+ act(() => { refresh(); refresh(); });+ expect(requests).toHaveLength(3);++ await resolveEvents(requests[2], 'Example refreshed event');+ await resolveEvents(requests[1], 'Example superseded refresh');+ expect(chipFor('Example refreshed event')).toBeInTheDocument();+ expect(screen.queryByRole('button', { name: /Example superseded refresh/ })).not.toBeInTheDocument();++ act(() => { refresh(); });+ mounted.unmount();+ expect(socketMock.off).toHaveBeenCalledWith('calendar:sync:completed', refresh);+ await resolveEvents(requests[3], 'Example late event');+ expect(screen.queryByRole('button', { name: /Example late event/ })).not.toBeInTheDocument();+ });+});+it('requests the next local midnight on a daylight-saving transition day', async () => {vi.useFakeTimers({ toFake: ['Date'] });vi.setSystemTime(new Date(2026, 2, 8, 12));