Skip to content

fix: in adaptEventHandlers check inputProps[key] before calling#6969

Merged
ckifer merged 1 commit intorecharts:mainfrom
SvetlanaVesna:fix-on-mouse-enter-error
Feb 7, 2026
Merged

fix: in adaptEventHandlers check inputProps[key] before calling#6969
ckifer merged 1 commit intorecharts:mainfrom
SvetlanaVesna:fix-on-mouse-enter-error

Conversation

@SvetlanaVesna
Copy link
Contributor

@SvetlanaVesna SvetlanaVesna commented Feb 6, 2026

Description

The fix adds a typeof inputProps[key] === 'function' guard to adaptEventHandlers (line 1140 in src/util/types.ts), matching the existing pattern in adaptEventsOfChild. Previously, when a
consumer passed onMouseEnter: undefined (or any non-function event prop), adaptEventHandlers would include it in the output object and later attempt to call undefined(...), throwing a TypeError. Now it
simply skips non-function event props.

On line 1141, adaptEventHandlers does:

out[key] = newHandler || ((e: Event) => inputProps[key](inputProps, e));

When no newHandler is provided and inputProps[key] is undefined (e.g. onMouseEnter: undefined), the fallback lambda calls undefined(inputProps, e) which throws. Meanwhile, adaptEventsOfChild correctly
guards with typeof item === 'function' on line 1170.

Related Issue

related issue: #6968

Motivation and Context

It solves the issue

How Has This Been Tested?

Screenshots (if appropriate):

Screen.Recording.2026-02-06.at.17.49.43.mov

Types of changes

  • Bug fix (non-breaking change which fixes an issue)
  • New feature (non-breaking change which adds functionality)
  • Breaking change (fix or feature that would cause existing functionality to change)

Checklist:

  • My change requires a change to the documentation.
  • I have updated the documentation accordingly.
  • I have added tests to cover my changes.
  • I have added a storybook story or VR test, or extended an existing story or VR test to show my changes

Summary by CodeRabbit

Bug Fixes

  • Fixed event handler validation to properly filter out non-function properties. The system now only processes callable event handlers, preventing potential issues when event handlers are set to undefined or other non-function values.

@coderabbitai
Copy link
Contributor

coderabbitai bot commented Feb 6, 2026

Walkthrough

AdaptEventHandlers now filters event props by requiring their values to be functions before including them. This prevents undefined event handlers from being called. The change is verified with a test and documented with a story.

Changes

Cohort / File(s) Summary
Type Logic Update
src/util/types.ts
Modified AdaptEventHandlers to add a stricter filter that only includes event props whose values are functions, preventing non-callable event properties from being passed as handlers.
Test Coverage
test/util/ReactUtils.spec.tsx
Added test case verifying adaptEventHandlers correctly skips event props that are not functions, validating behavior with onMouseEnter, onMouseLeave set to undefined and onClick set to a function.
Storybook Documentation
storybook/stories/Examples/LineChart/LineChart.stories.tsx
Added UndefinedEventHandlers story demonstrating the bug scenario where event handlers are explicitly set to undefined, showing how the utility now handles this case.

Estimated code review effort

🎯 2 (Simple) | ⏱️ ~12 minutes

Suggested reviewers

  • ckifer
🚥 Pre-merge checks | ✅ 3
✅ Passed checks (3 passed)
Check name Status Explanation
Title check ✅ Passed The title accurately summarizes the main change: adding a guard to check inputProps[key] before calling it in adaptEventHandlers, which directly matches the core fix in the changeset.
Docstring Coverage ✅ Passed No functions found in the changed files to evaluate docstring coverage. Skipping docstring coverage check.
Description check ✅ Passed The PR description provides a clear explanation of the bug fix, references the related issue, describes the motivation, and indicates that tests and storybook stories were added to cover the changes.

✏️ Tip: You can configure your own custom pre-merge checks in the settings.

✨ Finishing touches
  • 📝 Generate docstrings
🧪 Generate unit tests (beta)
  • Create PR with unit tests
  • Post copyable unit tests in a comment

Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

❤️ Share

Comment @coderabbitai help to get the list of available commands and usage tips.

@SvetlanaVesna SvetlanaVesna force-pushed the fix-on-mouse-enter-error branch from 469f1c7 to fde3870 Compare February 6, 2026 18:11
@SvetlanaVesna SvetlanaVesna marked this pull request as ready for review February 6, 2026 18:15
@codecov
Copy link

codecov bot commented Feb 6, 2026

Codecov Report

✅ All modified and coverable lines are covered by tests.
✅ Project coverage is 90.38%. Comparing base (108be69) to head (fde3870).
⚠️ Report is 3 commits behind head on main.

Additional details and impacted files
@@           Coverage Diff           @@
##             main    #6969   +/-   ##
=======================================
  Coverage   90.38%   90.38%           
=======================================
  Files         515      515           
  Lines       38497    38497           
  Branches     5338     5338           
=======================================
  Hits        34797    34797           
  Misses       3691     3691           
  Partials        9        9           

☔ View full report in Codecov by Sentry.
📢 Have feedback on the report? Share it here.

🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.

@ckifer ckifer merged commit 9bbc44b into recharts:main Feb 7, 2026
41 checks passed
@SvetlanaVesna SvetlanaVesna deleted the fix-on-mouse-enter-error branch February 9, 2026 10:01
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants