Skip to content

[scheduler] Fix the drag and drop of the day grid across DST transitions and speed up its preview - #23964

Merged
flaviendelangle merged 14 commits into
mui:masterfrom
flaviendelangle:scheduler-plain-date-drag-and-drop
Oct 23, 2026
Merged

flaviendelangle merged 14 commits into
mui:masterfrom
flaviendelangle:scheduler-plain-date-drag-and-drop

Conversation

@flaviendelangle

@flaviendelangle flaviendelangle commented Oct 22, 2026 •

Copy link
Copy Markdown
Member

This PR moves the drag and drop of the Event Calendar's day grid to plain dates and wall-clock times, after the recurring events in #23943. The day grid is the Month view and the all-day row of the Week and Day views: moving and resizing events across days, moving a timed event into the all-day row, and the preview drawn while dragging. It's independent of #23961, #23962 and #23963. The public API doesn't change.

Changes

  • useDayCellDropTarget() reads the days as plain dates in the display timezone and moves the dates on the wall clock, keeping their time of day. A move shifts them by whole days, and a resize moves them to the plain date of the cell with moveToPlainDate(). A time that a DST transition skips moves forward by the length of the gap, and a repeated one resolves to its first instant, like the wall times of [scheduler] Fix recurring events across timezones and DST transitions #23943.
  • getDraggedDay() in CalendarGridDayEvent counts the dates an event covers in its row, like the cells it's drawn on. It reads the first and last dates of the event from their timestamps, in the display timezone of the store. The drag data carries the grabbed day as a plain date instead of an adapter value. useEventOccurrencesWithDayGridPosition() counts the cells of an event in dates too, with the same lines as [scheduler] Speed up the day grid and fix day lists across DST transitions #23961, so that the event is drawn over the dates the drag counts.
  • The placeholder selectors and useCalendarGridPlaceholderInDay() compare timestamps and day numbers instead of calling isSameDay(), isWithinRange(), isBefore() and isAfter(). They run for every cell on every move of the pointer, where creating a plain date per cell made them twice as slow. The cells pass their processed day to isCreatingInDayCell() and usePlaceholderInDay(), which read its timestamp and key, with the display timezone of the store, instead of the adapter, and reuse it for a creation placeholder instead of processing it again.
  • drag-utils.ts gets moveToPlainDate() and addDaysOnWallClock(), which move adapter values on the wall clock with PlainDate. buildTemporalPlainDate() reads the offsets of the timezone instead of the getters of the adapter, and toLocalDayNumber() joins plain-date-utils, with the same lines as [scheduler] Speed up the day grid and fix day lists across DST transitions #23961, so that whichever lands second has nothing to merge.
  • A benchmark of the drag preview, which also runs on master.

Behavior changes

  1. Grabbing a timed event that spans several days by one of its last days moved it by one day too many. getDraggedDay() counted the full days from its start time, so an event from Monday 10:00 to Wednesday 09:00 lasted 2 days for it while it's drawn over 3 cells. Dropping its Wednesday part on Thursday moved it to Wednesday–Friday. It moves to Tuesday–Thursday now.
  2. Moving an event onto a day whose hour a DST transition repeats depended on the timezone of the system. An event at 02:30 dragged onto October 25th, 2026 in Europe/Paris was saved at 01:30Z on a UTC, New York or Havana system, and at 00:30Z on a Paris one. It's saved at the first 02:30, 00:30Z, everywhere.
  3. After a DST transition at midnight, in Havana, Santiago, Asunción or Beirut, the day starts at 01:00, and differenceInDays() could miss a day: dragging an event onto that day from a later one could move it one day short, or not at all. An event ending before 01:00 on a later day was also drawn one cell short: from March 9th, 2026 at 12:00 to March 10th at 00:30 in Havana, it covered March 9th only. It covers both days now.
  4. On some systems, the adapter's day math was wrong for other timezones: on a system in Pacific/Apia, December 30th, 2011 in another timezone counted as the same day as December 31st for the previews and the resizes, and on systems with their own DST transitions, a moved event could change its time of day by an hour.

Benchmarks

Mean times of pnpm bench:jsdom in packages/x-scheduler-internals with TZ=UTC: the placeholder selectors of the 42 cells of a month view, as they run on each move of the pointer while dragging a 3-day event. Master and this PR ran in turn, 5 times each, and each column is the median of their runs.

Scenario master This PR Speedup
System timezone 0.036 ms 0.016 ms 2.3×
New York display timezone 2.13 ms 0.034 ms 63×

In a named timezone, each isSameDay() built new TZDate values, which took over 2 ms of each frame.

Bundle size

Measured from source with esbuild, minified, with third-party packages external and without the error minifier, gzip level 9.

Entry master This PR Difference
event-calendar 69.69 kB 74.67 kB +4.98 kB
event-calendar-premium 86.95 kB 87.10 kB +0.15 kB
event-timeline-premium 92.17 kB 92.12 kB −0.05 kB

The community package now bundles PlainDate, which accounts for the 5 kB. The premium packages already did.

Adapter usage

Counted like in #23943. The references go from 523 to 511, and getMonth is gone. The PR removes 37 references to calendar math and comparisons. Reading the timestamps and timezones of the values adds 25 getTime() and getTimezone() references, which read a field of the TZDate. The getTime() ones read the dates of the placeholder and the bounds of the rows and columns, which have no processed version. The processed days and events carry no timezone, so their dates come from their timestamps and the display timezone of the store.

Method or property master This PR Difference
isSameDay 27 20 −7
addDays 36 31 −5
isAfter 16 11 −5
startOfDay 44 40 −4
isBefore 28 24 −4
differenceInDays 15 10 −5
endOfDay 23 21 −2
addMilliseconds, isWithinRange 21 19 −2
getDate, getYear, getMonth 10 7 −3
getTime 56 76 +20
getTimezone 8 13 +5

Validation

  • pnpm test:unit --project "x-scheduler*" --run: 3,791 passed, and pnpm test:browser --project "x-scheduler-internals*" --run: 2,417 passed. The Month view popover test that times out under load passes alone. The new tests of the timed multi-day event and of the repeated hour on a New York system fail on master.

  • After merging master, the RTL drag test of the Month view passes in the browser, and the tests that timed out in a full run on a loaded machine pass alone.

  • A randomized harness, not committed, compared the new code with master's on 5,000 random cases under each of 8 system timezones (UTC, New York, Paris, Lord Howe, Havana, Kolkata, Apia and Santiago), across 10 display timezones and around their DST transitions: the 4 placeholder selectors, the moves and resizes of the day cells, the moves of timed events into the day grid and the grabbed day. Every difference falls into one of the behavior changes above. It found the same on the final version of this PR.

  • Review rounds with Codex and the base-ui-review skill:

    • The first four asked for a test of the move onto a day whose midnight a DST transition skips, which fails on master, and the others approved.
    • A /simplify pass then passed the grabbed day as a day number and merged the branches of the drop target that move events. The grabbed day and the days of the drop target then became plain dates.
    • Three more rounds approved without findings. A last /simplify pass kept day numbers only in the selectors that run for every cell, and compared the dates once per resize.
  • TypeScript, ESLint and Prettier pass.

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

🤖 Generated with Claude Code

…ons and speed up its preview

Move the drop target of the day cells, the grabbed day of the day grid
events and the placeholder selectors to day numbers and wall-clock times.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
@flaviendelangle flaviendelangle added type: bug It doesn't behave as expected. performance scope: scheduler Changes related to the scheduler. labels Oct 22, 2026
@flaviendelangle flaviendelangle self-assigned this Oct 22, 2026
@code-infra-dashboard

code-infra-dashboard Bot commented Oct 22, 2026 •

Copy link
Copy Markdown

Deploy preview

https://deploy-preview-23964--material-ui-x.netlify.app/
QR code for https://deploy-preview-23964--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-scheduler 🔺+9.31KB(+2.22%) 🔺+3.45KB(+3.00%)
@mui/x-scheduler-premium 🔺+346B(+0.06%) 🔺+173B(+0.10%)
@mui/x-chat 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.

flaviendelangle and others added 2 commits October 22, 2026 18:32
…ansition skips

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
…holders

`usePlaceholderInDay()` and `isCreatingInDayCell()` receive the processed
day of the cell and read its timestamp and key instead of the adapter.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
flaviendelangle and others added 9 commits October 22, 2026 20:37
…simplify the drop target

- `CalendarGridDayEvent` passes the grabbed day as a day number, which the drop
  target compares with the day of the cell, instead of an adapter value it
  converted back.
- One branch moves the day grid and time grid events, and `moveToDay()` moves
  the resized edges.
- A resize onto the other edge's day uses `getStartOfDayMs()` and
  `getEndOfDayMs()`, and `getProcessedDayNumber()` reads the day of a
  processed date.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Duplicates the helpers of mui#23961 instead of keeping its own: the offset-based
`buildTemporalPlainDate()` and `toLocalDayNumber()`, with the same lines so that
whichever lands second merges cleanly. The drop target moves dates onto plain
dates, and the placeholders keep day numbers for the days of the cells.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
- The grabbed day and the span of the placeholder read plain dates. Only the
  selectors that run for every cell keep day numbers.
- Moving an event by days no longer throws past December 31st, 9999, which the
  month grid shows.
- The resize branches compare the dates once, and external events are handled
  before reading the day of the cell.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
… day

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
…day grid PR

`useEventOccurrencesWithDayGridPosition()` counts the dates of a span
from the timestamps of its end and of the day, with `toLocalDayNumber()`,
in the same lines as mui#23961, instead of building a plain date for each
day. Whichever PR lands second has nothing to merge there.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
… date

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Dates after December 31st, 9999 aren't supported, so `addDaysOnWallClock()` moves the date with `add()` instead of building it from its day number, and the test of a move past the last supported day goes.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
@github-actions github-actions Bot added the PR: out-of-date The pull request has merge conflicts and can't be merged. label Oct 23, 2026
@github-actions

Copy link
Copy Markdown
Contributor

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

flaviendelangle and others added 2 commits October 23, 2026 17:49
…of the store

The day event, the day placeholder and the placeholder selectors read the day of a processed date
from its timestamp and the display timezone of the store, instead of reading its value through
the adapter. The day cell drop target reuses the timezone of the cell for the dragged event.

The selector tests build their days in UTC, so their store now displays UTC, like a real store
builds its days in its display timezone.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
@github-actions github-actions Bot removed the PR: out-of-date The pull request has merge conflicts and can't be merged. label Oct 23, 2026
@rita-codes

Copy link
Copy Markdown
Member

I found no bugs: I compared the placeholder selectors, moves, resizes and timed → all-day moves with master across system and display timezones around DST, and every difference is one of the listed behavior changes. A few things on the tests and the description:

🟡 No test has a display day that differs from the UTC day. Replacing the display timezone with 'UTC' in getDraggedDay(), the grabbed day of a timed event in useDayCellDropTarget(), the placeholder selectors, the placeholder daySpan, useEventOccurrencesWithDayGridPosition() or the creation placeholder keeps every test green, since the non-UTC tests use wall times on the same date as in UTC. A drag of an evening event in America/New_York, or a morning one in Asia/Tokyo, would pin it.

🟡 The resize branches aren't pinned. Nothing resizes onto the day of the other edge or past it, nothing resizes the start across DST, and nothing lands a time that a DST transition skips: moving the gap backward instead of forward keeps the tests green.

ℹ️ The description says that whichever of this PR and #23961 lands second has nothing to merge, but they conflict in plain-date-utils/adapter.ts, useEventOccurrencesWithDayGridPosition.ts and its test, where the testHook signatures differ and both PRs add nearly the same Havana test.

ℹ️ The master column of the benchmark can't come from the committed file: it passes processed days to the placeholder selectors, which take adapter values on master, so no cell matches there. With adapter values on master, I get about the same speedup (≈2× and ≈75×).

@flaviendelangle
flaviendelangle merged commit 215513c into mui:master Oct 23, 2026
23 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

performance scope: scheduler Changes related to the scheduler. type: bug It doesn't behave as expected.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants