Skip to content
Merged
Show file tree
Hide file tree
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
8 changes: 7 additions & 1 deletion src/components/LinearCalendar.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -491,6 +491,11 @@ export default function LinearCalendar({ events: initialEventsProp, startDate, e
params.delete('start');
params.delete('end');
params.set('year', String(year));
// Rebuild `calendars` from component state (the source of truth) rather
// than trusting the URL, which may not have committed the most recent
// toggle yet — otherwise the holidays/Hebrew-date overlays get dropped
// on the first year change after enabling them.
applyCalendarsParam(params, { regularIds: visibleCalendarIds, showJewishCalendar, showHebrewDate });
router.push(`/?${params.toString()}`);
};

Expand All @@ -515,7 +520,8 @@ export default function LinearCalendar({ events: initialEventsProp, startDate, e
params.delete('year');
params.set('start', format(newStart, 'yyyy-MM'));
params.set('end', format(newEnd, 'yyyy-MM'));

// Preserve the overlays/visible calendars from state (see changeYear).
applyCalendarsParam(params, { regularIds: visibleCalendarIds, showJewishCalendar, showHebrewDate });
router.push(`/?${params.toString()}`);
};

Expand Down
17 changes: 17 additions & 0 deletions src/lib/calendar-params.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -91,4 +91,21 @@ describe('applyCalendarsParam', () => {
expect(ids).toContain('work');
expect(ids).toContain(JEWISH_CALENDAR_ID);
});

// Regression: changing the year must keep the overlays even when the URL
// hasn't committed the most recent toggle yet — by rebuilding `calendars`
// from component state, not from the (stale) URL.
it('year navigation rebuilds overlays from state over a stale URL', () => {
const params = new URLSearchParams('calendars=primary&year=2026'); // URL missing overlays
params.set('year', '2027');
applyCalendarsParam(params, {
regularIds: ['primary'],
showJewishCalendar: true, // state says they ARE on
showHebrewDate: true,
});
const ids = params.get('calendars')!.split(',');
expect(ids).toContain(JEWISH_CALENDAR_ID);
expect(ids).toContain(HEBREW_DATE_ID);
expect(params.get('year')).toBe('2027');
});
});
Loading