Skip to content

[scheduler] Recalculate DayTimeGrid hasScroll on container resize#22780

Merged
noraleonte merged 1 commit into
mui:masterfrom
Anexus5919:fix/day-time-grid-has-scroll-resize
Jun 12, 2026
Merged

[scheduler] Recalculate DayTimeGrid hasScroll on container resize#22780
noraleonte merged 1 commit into
mui:masterfrom
Anexus5919:fix/day-time-grid-has-scroll-resize

Conversation

@Anexus5919

Copy link
Copy Markdown
Contributor

Closes #22758

Summary

DayTimeGrid (the time grid shared by the Week and Day views) reserves a scrollbar-gutter placeholder in the all-day header and the last day-header cell so those columns stay aligned with the scrollable body below. That placeholder is toggled by a hasScroll flag, surfaced as data-has-scroll.

hasScroll was only recomputed when the events changed. It never recomputed when the container resized, so a resize that crossed the body's vertical-overflow threshold without an event change left hasScroll stale, and the all-day header columns drifted from the body columns by about one scrollbar width.

Root cause

hasScroll was measured in a single layout effect keyed only on occurrencesMap, with no resize signal:

useIsoLayoutEffect(() => {
  ...
  setHasScroll(body.scrollHeight > body.clientHeight);
}, [occurrencesMap]); // recomputes on events, not on container size

So a window resize, a side-panel toggle, or any height change that did not also change the events was ignored.

Fix

Extract the measurement into a stable callback and drive it from both signals: the existing layout effect (events) and a ResizeObserver on the body (size). This reuses useResizeObserver from @mui/x-internals, which the sibling MonthView already uses, and mirrors the existing find-and-measure idiom in GridMultiselectMeasurer.

const updateHasScroll = React.useCallback(() => {
  const body = bodyRef.current;
  const allDayHeader = allDayHeaderWrapperRef.current;

  if (!body || !allDayHeader) {
    return;
  }

  setHasScroll(body.scrollHeight > body.clientHeight);
}, []);

useIsoLayoutEffect(updateHasScroll, [occurrencesMap, updateHasScroll]);

useResizeObserver(bodyRef, updateHasScroll);

The layout effect is intentionally kept rather than replaced. A ResizeObserver on the body alone is not guaranteed to catch the all-day-events-grow case in every consumer layout (it only shrinks the body when the container is height-capped), so keeping the occurrencesMap recompute guarantees that path stays covered. The fix is local to DayTimeGrid and benefits both the Week and Day views, since both render this component. No new dependency is added.

Testing

Added a browser test at packages/x-scheduler/src/internals/components/day-time-grid/tests/DayTimeGrid.test.tsx. It is gated with describe.skipIf(isJSDOM) because hasScroll depends on real layout, which jsdom does not implement.

The test renders the week view in a tall host so the body does not overflow (data-has-scroll absent), then shrinks the container through direct DOM mutation so the body overflows without a React re-render, and asserts data-has-scroll appears. Resizing through the DOM rather than a React re-render is deliberate: a rerender re-runs the component and masks the bug, so it would not actually exercise the resize path.

Verified:

  • Passes with the fix.
  • Fails without the fix (expected ... to have an attribute 'data-has-scroll'), proving it catches the regression.
  • pnpm --filter "@mui/x-scheduler" run typescript, pnpm eslint, and the full pnpm test:unit --project "x-scheduler" --run jsdom suite all pass with no regressions.

Run it with:

pnpm test:browser --project "x-scheduler" --run DayTimeGrid

Out of scope

While in this file I noticed two pre-existing, unrelated issues that I deliberately did not change to keep this PR scoped: a malformed selector &:not[data-has-scroll] at DayTimeGrid.tsx:79 (should be &:not([data-has-scroll])), and a dead --has-scroll: 1 custom property at DayTimeGrid.tsx:38. These can be addressed separately.

Changelog

@mui/x-scheduler

  • Fix DayTimeGrid so the all-day header scrollbar gutter recalculates on container resize, keeping the header columns aligned with the scrollable body.

Checklist

  • 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.

@Anexus5919

Copy link
Copy Markdown
Contributor Author

@rita-codes @zannager Kindly have a review when you get time. Thanks!

@code-infra-dashboard

Copy link
Copy Markdown

Deploy preview

https://deploy-preview-22780--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.

@rita-codes rita-codes added type: enhancement It’s an improvement, but we can’t make up our mind whether it's a bug fix or a new feature. scope: scheduler Changes related to the scheduler. labels Jun 11, 2026
@rita-codes rita-codes changed the title fix(scheduler): recalculate DayTimeGrid hasScroll on container resize [scheduler] Recalculate DayTimeGrid hasScroll on container resize Jun 11, 2026

@noraleonte noraleonte left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Thank you for your contribution! 🎉 The fix looks good to me 👌

@noraleonte
noraleonte merged commit 244eef9 into mui:master Jun 12, 2026
24 of 25 checks passed
mbrookes pushed a commit to mbrookes/mui-x that referenced this pull request Jun 27, 2026
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] DayTimeGrid hasScroll not recalculated on container resize

3 participants