Skip to content
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 2 additions & 1 deletion components/schedule/ScheduleContainer.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,8 @@ export default function ScheduleContainer({ initialSchedule, year }: Readonly<Sc
return initialSchedule;
}

const filterSessions = (sessions: GridSession[]) => sessions.filter((s) => savedSessionIds.includes(s.id) || s.isServiceSession);
const savedIdsSet = new Set(savedSessionIds);
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

medium

To prevent potential runtime crashes, it is safer to defensively verify that savedSessionIds is an array before passing it to new Set(). Since savedSessionIds is loaded from localStorage in ScheduleProvider without explicit validation that the parsed JSON is indeed an array, any corrupted or non-array value (such as an object {}) in localStorage would cause new Set(savedSessionIds) to throw a TypeError and crash the application.

Suggested change
const savedIdsSet = new Set(savedSessionIds);
const savedIdsSet = new Set(Array.isArray(savedSessionIds) ? savedSessionIds : []);

const filterSessions = (sessions: GridSession[]) => sessions.filter((s) => savedIdsSet.has(s.id) || s.isServiceSession);

return initialSchedule.map((day) => ({
...day,
Expand Down
Loading