Skip to content

[charts] Remove compatibility layer for React vs native events#21780

Draft
JCQuintas wants to merge 11 commits intomui:masterfrom
JCQuintas:pointer-handlers
Draft

[charts] Remove compatibility layer for React vs native events#21780
JCQuintas wants to merge 11 commits intomui:masterfrom
JCQuintas:pointer-handlers

Conversation

@JCQuintas
Copy link
Member

Summary

  • Centralizes pointer interaction handling in ChartsLayerContainer instead of attaching event handlers to individual chart items (bars, lines, marks, heatmap cells)
  • Removes the heatmap shouldRegisterPointerInteractionsGlobally compatibility layer added in [charts-pro] Prefer global pointer interaction tracker in Heatmap  #20697
  • Adds getItemAtPosition to bar and line series configs, enabling container-level hit detection for these chart types
  • Refactors useRegisterPointerInteractions to iterate through all series configs rather than requiring per-chart-type registration

Breaking changes

  • BarPlot.onItemClick now receives a native MouseEvent instead of React.MouseEvent
  • useInteractionItemProps no longer accepts a skip parameter
  • Heatmap custom cell slots with onPointerEnter in slotProps no longer fall back to item-level event handlers

Closes #20957

Centralize pointer interaction handling in ChartsLayerContainer instead
of attaching event handlers to individual chart items. The hook now
iterates through all series configs' getItemAtPosition to find the item
at the pointer position.

- Refactor useRegisterPointerInteractions to iterate through series configs
- Add getItemAtPosition to bar and line series configs
- Remove skip parameter from useInteractionItemProps
- Add DOMMatrix fallback in getChartPoint for JSDOM environments
Remove shouldRegisterPointerInteractionsGlobally and always use
container-level pointer tracking for heatmap interactions. The compat
layer was added in v8 to support custom cell slots with item-level
event handlers.
Remove useInteractionItemProps from BarElement and per-item
useRegisterPointerInteractions from BatchBarPlot/IndividualBarPlot.
Pointer interactions are now handled centrally by ChartsLayerContainer.

BREAKING CHANGE: BarPlot onItemClick now receives a native MouseEvent
instead of React.MouseEvent.
Remove useInteractionItemProps from MarkElement, CircleMarkElement,
LineElement, and AreaElement. Pointer interactions are now handled
centrally by ChartsLayerContainer using getItemAtPosition.
Remove skip parameter usage from PieArc and per-component
useRegisterPointerInteractions from CandlestickPlot. These are now
handled centrally.
@JCQuintas JCQuintas added breaking change Introduces changes that are not backward compatible. 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: charts Changes related to the charts. labels Mar 18, 2026
@mui-bot
Copy link

mui-bot commented Mar 18, 2026

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

Updated pages:

Bundle size report

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 🔺+358B(+0.10%) 🔺+134B(+0.12%)
@mui/x-charts-pro ▼-334B(-0.07%) ▼-159B(-0.11%)
@mui/x-charts-premium ▼-781B(-0.15%) ▼-271B(-0.18%)
@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%)

Details of bundle changes

Generated by 🚫 dangerJS against 04ddc86

@codspeed-hq
Copy link

codspeed-hq bot commented Mar 18, 2026

Merging this PR will improve performance by 11.59%

⚠️ Different runtime environments detected

Some benchmarks with significant performance changes were compared across different runtime environments,
which may affect the accuracy of the results.

Open the report in CodSpeed to investigate

⚡ 2 improved benchmarks
✅ 12 untouched benchmarks

Performance Changes

Mode Benchmark BASE HEAD Efficiency
Simulation Heatmap: 100x100 grid 9.9 s 8.9 s +11.59%
Simulation LineChart with big data amount (with marks) 1.6 s 1.5 s +8.81%

Comparing JCQuintas:pointer-handlers (04ddc86) with master (8c684af)

Open in CodSpeed

Comment on lines +152 to +159
const barRect = bars[0].getBoundingClientRect();
await user.pointer({
target: bars[0],
coords: {
clientX: barRect.left + barRect.width / 2,
clientY: barRect.top + barRect.height / 2,
},
});
Copy link
Member Author

Choose a reason for hiding this comment

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

user.pointer() creates events with clientX/clientY defaulting to (0, 0), so we need to explicitly set them now.

This is because under the hood it doesn't fire real events, it only checks if the target has changed and fires the events that would supposedly happen from that.

Now we need to manually move the pointer to where we need.

@github-actions github-actions bot added the PR: out-of-date The pull request has merge conflicts and can't be merged. label Mar 18, 2026
@github-actions
Copy link
Contributor

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

@github-actions github-actions bot removed the PR: out-of-date The pull request has merge conflicts and can't be merged. label Mar 18, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

breaking change Introduces changes that are not backward compatible. scope: charts Changes related to the charts. 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.

[charts] Remove compatibility layer for React vs native events

2 participants