[scheduler] Recompute nowUpdatedEveryMinute only on timezone change#22793
Merged
rita-codes merged 2 commits intoJun 12, 2026
Merged
Conversation
|
You have reached your Codex usage limits for code reviews. You can see your limits in the Codex usage dashboard. |
Contributor
Author
|
@rita-codes @zannager Kindly have a review on this whenever you get time. Thanks! |
Deploy previewBundle size
Check out the code infra dashboard for more information about this PR. |
Member
|
Approach looks right to me! Tests across all three store classes are good coverage 🙌 Thanks for fixing this! 🙇 |
rita-codes
approved these changes
Jun 12, 2026
nowUpdatedEveryMinute only on timezone change
mbrookes
pushed a commit
to mbrookes/mui-x
that referenced
this pull request
Jun 27, 2026
…mui#22793) Co-authored-by: Rita <[email protected]>
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Closes #22765
Summary
SchedulerStore.updateStateFromParametersreassignednowUpdatedEveryMinute = adapter.now(...)on every parameter change.adapter.now()returns a fresh object reference each call, so any prop change (view, visibleDate, events, and so on) gavenowa new reference, even when nothing time related changed. This PR makes that recompute conditional on a realdisplayTimezonechange, leaving the once per minute timer as the sole owner of the periodic refresh.Root cause
The store already maintains
nowUpdatedEveryMinutewith a minute aligned timer set up in the constructor. The unconditional line inupdateStateFromParametersfought that design: it ran on essentially every render, because the three calling hooks (useEventCalendar,useEventCalendarPremium,useEventTimelinePremium) invokeupdateStateFromParametersfrom a layout effect keyed on the wholeparametersobject.The user visible cost is wasted re-renders. The
schedulerNowSelectors.nowUpdatedEveryMinuteselector is a pass through whose output is thenowreference itself.base-ui'suseStorecompares each selector output withObject.is, so a new reference forces a re-render of every current time consumer (the current time indicator, agenda view, mini calendar, and day time grid) on changes that have nothing to do with time.Changes
packages/x-scheduler-internals/src/internals/utils/SchedulerStore/SchedulerStore.tsThis is safe because
Store.update()is a shallow merge: omittingnowUpdatedEveryMinutefrom the partial preserves the existing reference. The comparison reads the previousthis.state.displayTimezone, sinceupdate()runs afterward. Recomputing on a genuine timezone change stays correct, becausenowis timezone stamped and would otherwise show the wrong wall clock until the next minute tick.The fix lives in the base
SchedulerStore, so all store variants (Event Calendar, Event Calendar Premium, Event Timeline Premium) benefit through the one change.Alternative considered
Also guarding on
adapter !== this.state.adapterwas considered and rejected. The adapter only changes identity whendateLocalechanges, and the date-fns adapter's comparison methods (now,isSameDay,isBefore,isEqual) take no locale argument, so anowvalue stays valid across a locale change. Adding that guard would reintroduce a slice of the churn for no correctness benefit.Tests
Added two cases to
core.SchedulerStore.test.ts, in the existingupdaterblock, which run across all store classes viastoreClasses.forEach:nowUpdatedEveryMinutekeeps the same reference when a non-timezone parameter changes.nowUpdatedEveryMinuteis recomputed, and correctly zoned, whendisplayTimezonechanges.Reverting the fix makes the first test fail with a reference inequality across all three store classes, confirming the test catches the regression.
Verification run locally: full
x-scheduler-internalssuite (790 passed, 3 skipped), fullx-scheduler-internals-premiumsuite (443 passed), TypeScript clean for@mui/x-scheduler-internals, ESLint clean, Prettier clean.Changelog
@mui/x-schedulerAvoid resetting the scheduler's "now" value (and the unnecessary re-renders it caused) on parameter changes that do not change the display timezone.
I have followed (at least) the PR section of the contributing guide.