diff --git a/.jules/bolt.md b/.jules/bolt.md index 231af188b..db4b8caf7 100644 --- a/.jules/bolt.md +++ b/.jules/bolt.md @@ -10,3 +10,7 @@ ## 2024-05-24 - Memoizing inline array maps **Learning:** Inline mapping of arrays inside JSX in large React components causes O(N) recalculation on every render. **Action:** Wrap inline JSX elements that map over arrays (e.g., lists of tasks) in a `useMemo` hook with specific dependencies. + +## 2025-02-13 - Memoizing Calendar Grid Generation +**Learning:** Inline mapping of arrays inside JSX in large React components, such as a 35-cell calendar grid, causes O(N) recalculation on every render. +**Action:** Wrap inline JSX elements that map over arrays (e.g., generating calendar cells) in a `useMemo` hook with specific dependencies to prevent rendering bottlenecks when other unrelated state variables are updated. diff --git a/frontend/src/components/calendar/CalendarMonthView.tsx b/frontend/src/components/calendar/CalendarMonthView.tsx index ae8b731d6..c7af62aa8 100644 --- a/frontend/src/components/calendar/CalendarMonthView.tsx +++ b/frontend/src/components/calendar/CalendarMonthView.tsx @@ -20,6 +20,23 @@ export function CalendarMonthView({ visibleMonthEvents }: Props) { return grouped; }, [visibleMonthEvents]); + // ⚡ Bolt: Wrap calendar grid generation in useMemo to prevent O(N) re-renders + const calendarCells = useMemo(() => ( + Array.from({ length: 35 }).map((_, i) => { + const dayEvents = monthEventsByDay.get(i) ?? []; + return ( +
+ {i < 31 ? i + 1 : ''} + {dayEvents.map((event) => ( +
+ {event.time} {event.title} +
+ ))} +
+ ); + }) + ), [monthEventsByDay]); + return (
@@ -27,19 +44,7 @@ export function CalendarMonthView({ visibleMonthEvents }: Props) {
{/* Simulated Grid Cells */} - {Array.from({ length: 35 }).map((_, i) => { - const dayEvents = monthEventsByDay.get(i) ?? []; - return ( -
- {i < 31 ? i + 1 : ''} - {dayEvents.map((event) => ( -
- {event.time} {event.title} -
- ))} -
- ); - })} + {calendarCells}
);