Skip to content

[scheduler] Validate missing and duplicate event ids#22790

Merged
rita-codes merged 8 commits into
mui:masterfrom
Anexus5919:fix/scheduler-validate-event-ids
Jun 15, 2026
Merged

[scheduler] Validate missing and duplicate event ids#22790
rita-codes merged 8 commits into
mui:masterfrom
Anexus5919:fix/scheduler-validate-event-ids

Conversation

@Anexus5919

Copy link
Copy Markdown
Contributor

Closes #22759

Summary

buildEventsState inserted events into the id lookups without validating the resolved id, so duplicate or missing ids silently corrupted the scheduler state with no feedback:

  • Duplicate ids: the second event overwrote the first in eventModelLookup and processedEventLookup, but eventIdList kept both copies. The array and the lookups disagreed, which surfaced as duplicate React keys (occurrences are keyed by String(event.id)) and events rendering with another event's data.
  • Missing ids: when the resolved id was undefined, every id-less event collided on the same key, so only one survived. Silent data loss.

The premium lazy-loading cache had the same gap: its default getId returns event.id, and upsert keyed entries by String(this.getId(event)), so id-less events all collapsed onto the literal "undefined" key and could be wrongly evicted as server-side deletes.

SchedulerEvent.id is typed as required, so TypeScript users are nudged at compile time. The real victims are JavaScript users, dynamically sourced data, and the dataSource path where ids resolve at runtime.

Changes

  • Add checkSchedulerEventIdIsValid(id, event) in SchedulerStore.utils.ts, mirroring the Data Grid's checkGridRowIdIsValid. It throws a clear MUI X Scheduler error (what happened, why it is a problem, how to fix it) when the id is null / undefined, including the offending event and pointing to eventModelStructure.idGetter as the per-event id source, or remains a valid id.
  • Use the helper in buildEventsState. On a missing id it throws. On a duplicate id it emits a dev-only warnOnce and skips re-pushing the id, so eventIdList stays consistent with the last-wins lookups. This removes the list/lookup mismatch and the duplicate React keys in production, not just in development.
  • Reuse the same helper in the premium cache's upsert, validating the resolved id before stringifying it. Because setRange funnels every event through upsert, this also fixes the wrong eviction of id-less events.

This keeps last-wins semantics for duplicates, matching the Data Grid's lenient direction, while fixing the scheduler-specific corruption that was worse than the Grid's (the Grid never diverged its id list from its lookup; the scheduler did).

Behavior

  • Missing id: throws MUI X Scheduler: All events must have a unique \id`...` (registered as error code 287).
  • Duplicate id: warns once in development, keeps the last event for that id, and renders it a single time.

Testing

  • event.SchedulerStore.test.ts: a missing id throws; two events sharing an id warn in dev, dedupe the id list, and keep the last event (verified across EventCalendarStore, EventCalendarPremiumStore, and EventTimelinePremiumStore).
  • dataSource.test.ts: upsert and setRange throw on a missing id instead of colliding on "undefined".
  • Ran pnpm extract-error-codes (added code 287), typecheck, eslint, and prettier.
  • Full suites for x-scheduler-internals and x-scheduler-internals-premium pass (1235 passed, 3 skipped).

How to reproduce

  1. Render a scheduler with two events without an id (or a dataSource whose getter cannot resolve one). Before this change one event silently disappears; after it throws a clear error.
  2. Render two events with the same id and different titles. Before this change the event renders twice with duplicate React keys and mismatched data; after it renders once with a dev warning.
  • 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 @flaviendelangle Kindly have a review on this pr whenever you get a chance. Thanks!

@Anexus5919 Anexus5919 changed the title fix(scheduler): validate missing and duplicate event ids [scheduler]: validate missing and duplicate event ids Jun 11, 2026
@code-infra-dashboard

code-infra-dashboard Bot commented Jun 11, 2026

Copy link
Copy Markdown

Deploy preview

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

@Anexus5919 Anexus5919 changed the title [scheduler]: validate missing and duplicate event ids [scheduler] validate missing and duplicate event ids Jun 11, 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.

@zannager zannager added the scope: scheduler Changes related to the scheduler. label Jun 12, 2026
@Anexus5919
Anexus5919 force-pushed the fix/scheduler-validate-event-ids branch from 179a858 to fb444a9 Compare June 12, 2026 16:05
@github-actions github-actions Bot removed the PR: out-of-date The pull request has merge conflicts and can't be merged. label Jun 12, 2026
@Anexus5919

Copy link
Copy Markdown
Contributor Author

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

Resolved.

@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/scheduler-validate-event-ids branch from fb444a9 to f8c8163 Compare June 12, 2026 19:49
@github-actions github-actions Bot removed the PR: out-of-date The pull request has merge conflicts and can't be merged. label Jun 12, 2026
@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.

Thanks for working on this @Anexus5919! The implementation looks great! left a couple of minor style nits below.
The rest is perfect 🚢

@github-actions github-actions Bot added the PR: out-of-date The pull request has merge conflicts and can't be merged. label Jun 15, 2026
@github-actions

Copy link
Copy Markdown
Contributor

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

Anexus5919 and others added 4 commits June 15, 2026 15:08
…ore/SchedulerStore.utils.ts

Co-authored-by: Rita <[email protected]>
Signed-off-by: Adarsh Singh <[email protected]>
…ore/tests/event.SchedulerStore.test.ts

Co-authored-by: Rita <[email protected]>
Signed-off-by: Adarsh Singh <[email protected]>
…ore/tests/event.SchedulerStore.test.ts

Co-authored-by: Rita <[email protected]>
Signed-off-by: Adarsh Singh <[email protected]>
@github-actions github-actions Bot removed the PR: out-of-date The pull request has merge conflicts and can't be merged. label Jun 15, 2026
@Anexus5919

Copy link
Copy Markdown
Contributor Author

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

Resolved.

@rita-codes
rita-codes merged commit 7ee510c into mui:master Jun 15, 2026
21 checks passed
@oliviertassinari oliviertassinari changed the title [scheduler] validate missing and duplicate event ids [scheduler] Calidate missing and duplicate event ids Jun 15, 2026
@oliviertassinari oliviertassinari changed the title [scheduler] Calidate missing and duplicate event ids [scheduler] Validate missing and duplicate event ids Jun 15, 2026
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] Duplicate / missing event ids silently overwrite state

3 participants