getLocalTimeZone cache #7195
Replies: 2 comments 4 replies
-
Looks like there is a proposal for a Not sure of a good solution for now, but maybe doing something with the Page Visibility API at the application level. I think that's too opinionated to be included by default though. |
Beta Was this translation helpful? Give feedback.
-
Sorry to comment on an old issue. I'm running into a similar issue where I'm trying to test something that relies on the user's local timezone. test.each([
['UTC', '...'],
['America/New_York', '...'],
])('it gets localized to users timezone (%s)', async (tz, expectedDate) => {
process.env.TZ = tz;
expect(...).toBe(...);
}); Using Would a The latter would allow user-defined logic to refresh the timezone based on polling etc in the other comment. |
Beta Was this translation helpful? Give feedback.
-
I noticed getLocalTimeZone internally caches the result, so it's only calculated once:
react-spectrum/packages/@internationalized/date/src/queries.ts
Lines 118 to 128 in 987f174
This was added in #2264, with a TODO about invalidating it somehow in the future (which has not been done, as far as I can see).
This can cause unexpected behaviour if the user happens to change timezone (e.g. they close their laptop in one timezone, go somewhere, open it in another timezone).
Does anyone have any insight as to why this was done, or whether it's a known issue? I can see #2264 mentions improving date formatting performance, so I can imagine caching is part of that, although I wonder how much the timezone calculation was contributing to the formatting as opposed to everything else.
Beta Was this translation helpful? Give feedback.
All reactions