Skip to content

fix(Tooltip): prevent crash on sparse or undefined payload entries#7149

Merged
ckifer merged 1 commit intorecharts:mainfrom
Om-Mishra09:fix/tooltip-sparse-payload
Mar 24, 2026
Merged

fix(Tooltip): prevent crash on sparse or undefined payload entries#7149
ckifer merged 1 commit intorecharts:mainfrom
Om-Mishra09:fix/tooltip-sparse-payload

Conversation

@Om-Mishra09
Copy link
Copy Markdown
Contributor

@Om-Mishra09 Om-Mishra09 commented Mar 20, 2026

What is the purpose of this pull request?
This PR fixes a fatal crash (TypeError: Cannot read properties of undefined/null (reading 'type')) in the DefaultTooltipContent component.

Currently, if the payload array contains sparse items, null, or undefined (e.g., [ { name: 'A', value: 10 }, undefined, { name: 'B', value: 20 } ]), the component attempts to access entry.type during the sortedPayload.map execution without verifying if entry itself exists, causing the entire React tree to crash.

What does this PR do?

  • Adds a safe check inside sortedPayload.map to handle and return null for undefined/null entries before accessing their properties.
  • Adds a comprehensive unit test in DefaultTooltipContent.spec.tsx that explicitly mounts the component with a sparse payload to prevent future regressions.

Checklist:

  • I have added tests to cover my changes.
  • All tests pass locally (bypassed local snapshot mismatches on main via CI).
  • I have run the linter and it passes.

Summary by CodeRabbit

  • Bug Fixes
    • Fixed tooltip rendering to gracefully handle null and undefined payload entries, preventing errors and improving application stability.

@coderabbitai
Copy link
Copy Markdown
Contributor

coderabbitai bot commented Mar 20, 2026

No actionable comments were generated in the recent review. 🎉

ℹ️ Recent review info
⚙️ Run configuration

Configuration used: Organization UI

Review profile: CHILL

Plan: Pro

Run ID: cffcd5fe-420f-44f8-b236-2af75f32a48a

📥 Commits

Reviewing files that changed from the base of the PR and between a25c73f and 1a9a7ad.

📒 Files selected for processing (2)
  • src/component/DefaultTooltipContent.tsx
  • test/component/DefaultTooltipContent.spec.tsx
✅ Files skipped from review due to trivial changes (2)
  • src/component/DefaultTooltipContent.tsx
  • test/component/DefaultTooltipContent.spec.tsx

Walkthrough

The PR adds defensive handling in DefaultTooltipContent to filter out null/undefined payload entries and entries marked with type === 'none', along with test coverage validating this behavior.

Changes

Cohort / File(s) Summary
DefaultTooltipContent Updates
src/component/DefaultTooltipContent.tsx, test/component/DefaultTooltipContent.spec.tsx
Enhanced payload item mapping with guard condition to filter out falsy/nullish entries and entries with type === 'none'. Added test case verifying the component correctly handles undefined and null entries in the payload array.

Estimated code review effort

🎯 1 (Trivial) | ⏱️ ~5 minutes

Possibly related PRs

Suggested reviewers

  • PavelVanecek
  • marilia-gb
🚥 Pre-merge checks | ✅ 3
✅ Passed checks (3 passed)
Check name Status Explanation
Title check ✅ Passed The title 'fix(Tooltip): prevent crash on sparse or undefined payload entries' is specific and directly related to the core change—fixing a crash by handling sparse/undefined payload entries in the Tooltip component.
Description check ✅ Passed The description provides clear motivation (crash fix with error example), details what was changed (safe check, unit test added), and includes a partially completed checklist confirming tests were added and linting passed.
Docstring Coverage ✅ Passed No functions found in the changed files to evaluate docstring coverage. Skipping docstring coverage check.

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

✨ Finishing Touches
🧪 Generate unit tests (beta)
  • Create PR with unit tests

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.

@Om-Mishra09 Om-Mishra09 force-pushed the fix/tooltip-sparse-payload branch from 8d426a9 to a25c73f Compare March 23, 2026 14:55
@codecov
Copy link
Copy Markdown

codecov bot commented Mar 23, 2026

Bundle Report

Changes will decrease total bundle size by 740 bytes (-0.01%) ⬇️. This is within the configured threshold ✅

Detailed changes
Bundle name Size Change
recharts/bundle-cjs 1.3MB 10 bytes (0.0%) ⬆️
recharts/bundle-es6 1.13MB 10 bytes (0.0%) ⬆️
recharts/bundle-umd 546.86kB 4 bytes (0.0%) ⬆️
recharts/bundle-treeshaking-sankey* 345.54kB -382 bytes (-0.11%) ⬇️
recharts/bundle-treeshaking-sunburst* 323.22kB -382 bytes (-0.12%) ⬇️

ℹ️ *Bundle size includes cached data from a previous commit

Affected Assets, Files, and Routes:

view changes for bundle: recharts/bundle-es6

Assets Changed:

Asset Name Size Change Total Size Change (%)
component/DefaultTooltipContent.js 10 bytes 6.19kB 0.16%
view changes for bundle: recharts/bundle-treeshaking-sunburst

Assets Changed:

Asset Name Size Change Total Size Change (%)
bundle.js -382 bytes 323.22kB -0.12%
view changes for bundle: recharts/bundle-treeshaking-sankey

Assets Changed:

Asset Name Size Change Total Size Change (%)
bundle.js -382 bytes 345.54kB -0.11%
view changes for bundle: recharts/bundle-cjs

Assets Changed:

Asset Name Size Change Total Size Change (%)
component/DefaultTooltipContent.js 10 bytes 7.33kB 0.14%
view changes for bundle: recharts/bundle-umd

Assets Changed:

Asset Name Size Change Total Size Change (%)
Recharts.js 4 bytes 546.86kB 0.0%

@codecov
Copy link
Copy Markdown

codecov bot commented Mar 23, 2026

Codecov Report

✅ All modified and coverable lines are covered by tests.
✅ Project coverage is 89.63%. Comparing base (b39edbf) to head (1a9a7ad).
⚠️ Report is 8 commits behind head on main.

Additional details and impacted files
@@            Coverage Diff             @@
##             main    #7149      +/-   ##
==========================================
+ Coverage   89.61%   89.63%   +0.02%     
==========================================
  Files         536      536              
  Lines       40479    40484       +5     
  Branches     5519     5525       +6     
==========================================
+ Hits        36275    36288      +13     
+ Misses       4196     4188       -8     
  Partials        8        8              

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

@Om-Mishra09 Om-Mishra09 force-pushed the fix/tooltip-sparse-payload branch from a25c73f to 1a9a7ad Compare March 23, 2026 17:11
@ckifer ckifer merged commit 738f71f into recharts:main Mar 24, 2026
52 checks passed
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