Skip to content

Commit a95683a

Browse files
committed
fix(scheduled-tasks): re-sync calendar day frame when timezone resolves
When useTimezone() resolves from the browser fallback to the saved account zone after mount, re-derive today (and the focused day, while it is still on today) so the grid frame, now-line, and fetched range stay in agreement. The focused day is preserved across the change once the user has navigated away.
1 parent 9371764 commit a95683a

1 file changed

Lines changed: 17 additions & 0 deletions

File tree

apps/sim/app/workspace/[workspaceId]/scheduled-tasks/hooks/use-calendar.ts

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -56,9 +56,26 @@ export function useCalendar(timezone: string): UseCalendarReturn {
5656
const [anchor, setAnchor] = useState<Date>(() => zonedClockDate(new Date(), timezone))
5757
const [selectedSlot, setSelectedSlot] = useState<CalendarSlot | null>(null)
5858
const [isCreateOpen, setIsCreateOpen] = useState(false)
59+
const todayRef = useRef(today)
5960

6061
useEffect(() => {
62+
todayRef.current = today
63+
}, [today])
64+
65+
/**
66+
* Re-sync to the effective zone's current day when `timezone` actually
67+
* changes — e.g. when `useTimezone()` resolves from the browser fallback to
68+
* the saved account zone after mount. The focused day follows only while it is
69+
* still on "today", so an in-progress navigation is preserved. Owning
70+
* `timezoneRef` here (instead of a separate sync effect) keeps the guard
71+
* honest: the ref still reflects the previous zone when this runs.
72+
*/
73+
useEffect(() => {
74+
if (timezoneRef.current === timezone) return
6175
timezoneRef.current = timezone
76+
const now = zonedClockDate(new Date(), timezone)
77+
setAnchor((current) => (isSameDay(current, todayRef.current) ? now : current))
78+
setToday(now)
6279
}, [timezone])
6380

6481
useEffect(() => {

0 commit comments

Comments
 (0)