Skip to content

[scheduler] Return a primitive key from the Calendar lazy-loading selector - #22791

Merged
rita-codes merged 6 commits into
mui:masterfrom
Anexus5919:fix/calendar-lazy-loading-primitive-key
Jun 16, 2026
Merged

rita-codes merged 6 commits into
mui:masterfrom
Anexus5919:fix/calendar-lazy-loading-primitive-key

Conversation

@Anexus5919

Copy link
Copy Markdown
Contributor

Closes #22763

Summary

The premium Calendar lazy-loading plugin's store-effect selector returned a fresh object literal on every call. Because SchedulerStore.registerStoreEffect compares selector results with reference equality (!==), a brand new object is never equal to the previous one, so the effect callback ran on every store notification (selection, hover, drag-placeholder moves), not just when the visible day range changed.

It was never a fetch storm, since the effect guarded internally on visibleDaysKey, but it churned work on a hot path: during a drag the store updates on every pointer move, so each frame rebuilt the joined key string, allocated a new object, and re-invoked the effect (which itself recomputed visibleDaysSelector a second time). The Timeline plugin already does this correctly by returning a primitive string.

Changes

The selector now returns a primitive, mirroring the Timeline plugin:

  • Returns null when no view is registered or there are no visible days.
  • Otherwise returns the joined visibleDaysKey string.

With a primitive return value, !== compares by value, so the effect only runs when the range actually changes. The unused isLoading field is dropped from the selected value.

Behavior preserved

  • Empty-view and unmount safety: the old visibleDays.length === 0 guard is kept as nextKey === null, so a view unmount (viewConfig resets to null) cannot schedule a fetch that would read an empty day list and throw on days[0].value.
  • Instant initial load: the old previous.viewConfig == null instant-load flag becomes previousKey === null, which is true exactly when no view was registered before (construction or after unmount). This requires returning null rather than an empty string for the empty case, otherwise '' === null would be false and the first load would silently fall back to the debounced path.

A note on the issue's secondary claim

The issue also suggested this fixes a case where the Calendar's first lazy-load "goes through the debounce instead of loading immediately." I could not reproduce that on master: viewConfig is null at construction, so previous.viewConfig == null is already true on the first real transition and the initial load is already instant. I verified this with a throwaway test before making any change. This PR therefore preserves the existing instant load rather than fixing a pre-existing bug, and adds a regression test so the instant load stays protected.

Testing

  • Added a test pinning the instant initial load (the Calendar suite had none).
  • Existing Calendar lazy-loading tests pass unchanged (6/6).
  • Full x-scheduler-internals-premium suite passes (444/444), tsc clean, eslint and prettier clean.

Changelog

Reduced wasted work on a hot path in the premium Event Calendar lazy loading: the lazy-loading effect no longer re-runs on unrelated store updates (selection, hover, drag), only when the visible date range changes.

  • I have followed (at least) the PR section of the contributing guide.

@chatgpt-codex-connector

Copy link
Copy Markdown

You have reached your Codex usage limits for code reviews. You can see your limits in the Codex usage dashboard.
To continue using code reviews, you can upgrade your account or add credits to your account and enable them for code reviews in your settings.

@code-infra-dashboard

code-infra-dashboard Bot commented Jun 11, 2026 •

Copy link
Copy Markdown

Deploy preview

https://deploy-preview-22791--material-ui-x.netlify.app/

Bundle size

Bundle Parsed size Gzip size
@mui/x-data-grid 0B(0.00%) 0B(0.00%)
@mui/x-data-grid-pro 0B(0.00%) 0B(0.00%)
@mui/x-data-grid-premium 0B(0.00%) 0B(0.00%)
@mui/x-charts 0B(0.00%) 0B(0.00%)
@mui/x-charts-pro 0B(0.00%) 0B(0.00%)
@mui/x-charts-premium 0B(0.00%) 0B(0.00%)
@mui/x-date-pickers 0B(0.00%) 0B(0.00%)
@mui/x-date-pickers-pro 0B(0.00%) 0B(0.00%)
@mui/x-tree-view 0B(0.00%) 0B(0.00%)
@mui/x-tree-view-pro 0B(0.00%) 0B(0.00%)
@mui/x-license 0B(0.00%) 0B(0.00%)

Details of bundle changes


Check out the code infra dashboard for more information about this PR.

@zannager zannager added the scope: scheduler Changes related to the scheduler. label Jun 12, 2026
@github-actions github-actions Bot added the PR: out-of-date The pull request has merge conflicts and can't be merged. label Jun 12, 2026
@github-actions

Copy link
Copy Markdown
Contributor

This pull request has conflicts, please resolve those before we can evaluate the pull request.

@Anexus5919
Anexus5919 force-pushed the fix/calendar-lazy-loading-primitive-key branch from 4a07264 to ef509bd Compare June 13, 2026 09:33
@github-actions github-actions Bot removed the PR: out-of-date The pull request has merge conflicts and can't be merged. label Jun 13, 2026
@Anexus5919

Copy link
Copy Markdown
Contributor Author

This pull request has conflicts, please resolve those before we can evaluate the pull request.

Resolved.

@Anexus5919

Copy link
Copy Markdown
Contributor Author

@rita-codes @zannager Kindly have a review on this pr. Thanks!

@rita-codes rita-codes added the type: enhancement It’s an improvement, but we can’t make up our mind whether it's a bug fix or a new feature. label Jun 15, 2026

@rita-codes rita-codes left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

Looks good to me! Thanks for taking care of this 🙇‍♀️

@rita-codes
rita-codes merged commit 18b12a6 into mui:master Jun 16, 2026
21 checks passed
mbrookes pushed a commit to mbrookes/mui-x that referenced this pull request Jun 27, 2026
…ector (mui#22791)

Co-authored-by: Rita <47579513+rita-codes@users.noreply.github.com>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

scope: scheduler Changes related to the scheduler. type: enhancement It’s an improvement, but we can’t make up our mind whether it's a bug fix or a new feature.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

[scheduler] Calendar lazy-loading store-effect selector returns a new object every update

3 participants