Skip to content

fix(web): preserve timezone from URL query param on reload (#1411)#1444

Open
krapcys1-maker wants to merge 1 commit intobaires:masterfrom
krapcys1-maker:fix/issue-1411-20260329071120
Open

fix(web): preserve timezone from URL query param on reload (#1411)#1444
krapcys1-maker wants to merge 1 commit intobaires:masterfrom
krapcys1-maker:fix/issue-1411-20260329071120

Conversation

@krapcys1-maker
Copy link
Copy Markdown

Fixes #1411

Summary

Fixes timezone reset to UTC on reload by honoring the existing tz query parameter in the page initialization flow.

Problem

When the page is reloaded with ?tz=, the UI timezone state was reinitialized to default UTC instead of the URL parameter.

What changed

  • Read tz from Next.js router query and apply it when valid.
  • Use router instance consistently for URL updates in timezone change handler.

Solution

The page now synchronizes timezone state with router query on mount/update, preserving expected timezone context across reload/open-in-new-tab scenarios.

Why

This aligns web behavior with the existing API/query behavior and avoids user-visible timezone drift.

Tests

  • npm test -- --runInBand tests/time.test.ts tests/days.test.ts

@krapcys1-maker krapcys1-maker requested a review from baires as a code owner March 29, 2026 07:12
@vercel
Copy link
Copy Markdown

vercel bot commented Mar 29, 2026

@krapcys1-maker is attempting to deploy a commit to the Alexis' projects Team on Vercel.

A member of the Team first needs to authorize it.

@krapcys1-maker
Copy link
Copy Markdown
Author

krapcys1-maker commented Mar 29, 2026

Tests and coverage both pass. The failure happens only at the final publish step of ArtiomTr/jest-coverage-report-action@v2 with HttpError: Bad credentials, so this looks like a CI token/permissions issue rather than a problem with the code changes.

Comment on lines +27 to 34
const queryTimezone = router.query.tz
const timezoneFromQuery = Array.isArray(queryTimezone) ? queryTimezone[0] : queryTimezone
if (timezoneFromQuery && Time.zoneExists(timezoneFromQuery)) {
setTimezone(timezoneFromQuery)
setNow(new Time(timezoneFromQuery))
}

const savedTheme = localStorage.getItem('theme') as ThemeType | null
Copy link
Copy Markdown
Owner

Choose a reason for hiding this comment

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

This added 2 mixed concerns in one effect, now we handle the theme + tz sync

Copy link
Copy Markdown
Owner

Choose a reason for hiding this comment

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

Also I think there will be a double render on load now

@krapcys1-maker
Copy link
Copy Markdown
Author

Thanks for the review! Addressed all comments:

1. This added 2 mixed concerns in one effect, now we handle the theme + tz sync
I kept theme handling isolated in its existing effect and moved timezone initialization out of effects entirely. The page now derives the initial timezone from router.query.tz during render, falling back to the tz prop when the query is missing or invalid. This avoids combining theme and timezone logic in one useEffect.

2. Also I think there will be a double render on load now
I removed timezone synchronization from the mount/update effect to avoid an extra state update on initial load. timezone and now are now initialized from the query-derived timezone up front, which prevents the extra render caused by setting timezone after mount. I also narrowed the remaining effect to respond only to router.query.date changes and restored the direct setNow(new Time(newTimezone)) update in changeTimezone so timezone changes still update the displayed time immediately.

Summary: Addressed both review comments by separating concerns and avoiding the extra initial render. Theme logic remains in its own effect, timezone is initialized directly from the router query, and time updates still work for both date query changes and manual timezone changes. Validated with the existing Jest test command.

All 1 validation command(s) passed.

@krapcys1-maker krapcys1-maker requested a review from baires April 2, 2026 03:47
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Website TZ parameter broke

2 participants