Skip to content

feat(Bar): support data prop directly on Bar, like Line/Area/Scatter - #7599

Merged
PavelVanecek merged 2 commits into
recharts:mainfrom
pratik-desgn:fix-bar-own-data
Jul 30, 2026
Merged

PavelVanecek merged 2 commits into
recharts:mainfrom
pratik-desgn:fix-bar-own-data

Conversation

@pratik-desgn

@pratik-desgn pratik-desgn commented Jul 29, 2026 •

Copy link
Copy Markdown
Contributor

Summary

<Bar> silently ignored a data prop set directly on it, and would fail to render entirely when the parent chart had no top-level data — even though Line, Area, and Scatter all support per-item data via the DataProvider interface. Fixes #3985 (and the closely related #1699, #3504).

Root cause: Bar.tsx registers its settings with the store via SetCartesianGraphicalItem, but hardcoded data={undefined} regardless of what was actually passed to <Bar data={...}> — with a comment literally questioning why ("Bar does not allow setting data directly on the graphical item (why?)"). The selector layer (selectBarRectangles in barSelectors.ts) already had full support for falling back to item-level data when present; it just never received any because of this one line.

Changes

  • BarProps now extends DataProvider<DataPointType> (matching Line/Area/Scatter), so data is a properly typed prop.
  • SetCartesianGraphicalItem now reports props.data instead of a hardcoded undefined.

Test plan

  • Added a regression test confirming Bar's own data prop is reported to the Redux store.
  • Added a rendering regression test confirming <Bar data={...}> renders correctly even when the parent chart has no top-level data.
  • Full test/cartesian/Bar suite passes (123/123).
  • Full test/cartesian, test/chart, test/state suites pass with no regressions (2394+ tests).
  • tsc --noEmit clean.
  • eslint clean.

Summary by CodeRabbit

  • Bug Fixes
    • Bars now correctly use data provided directly to the Bar component, even when no chart-level data is present.
    • Bar-associated settings now retain the provided data for consistent state integration and rendering.
  • Tests
    • Added new state integration and rendering coverage to verify Bar behavior with own data.
    • Updated omnidoc prop reader snapshot expectations to include the data prop for Bar.

Bar registered its per-item settings with data hardcoded to undefined,
even though the store selectors (selectBarRectangles) already knew how
to fall back to item-level data when present. This meant <Bar data={...}>
silently did nothing, and Bar would fail to render at all when the parent
chart had no top-level data prop (recharts#3985).

Line, Area, and Scatter already support this via the DataProvider
interface; Bar now does too.
@coderabbitai

coderabbitai Bot commented Jul 29, 2026 •

Copy link
Copy Markdown
Contributor

Review Change Stack

Walkthrough

Bar now accepts its own data through BarProps, stores it in the registered cartesian graphical item, and renders from that data when chart-level data is absent. Tests cover state propagation, rendering, and prop-reader snapshots.

Changes

Bar data propagation

Layer / File(s) Summary
Bar data contract and registration
src/cartesian/Bar.tsx
BarProps extends DataProvider, and Bar registers props.data with SetCartesianGraphicalItem.
Bar-owned data validation
test/cartesian/Bar/Bar.spec.tsx, omnidoc/readProject.spec.ts
Tests verify state propagation and rendering without chart-level data; Bar prop snapshots include data.

Estimated code review effort: 2 (Simple) | ~10 minutes

Possibly related PRs

Suggested reviewers: pavelvanecek, ckifer

🚥 Pre-merge checks | ✅ 5
✅ Passed checks (5 passed)
Check name Status Explanation
Linked Issues check ✅ Passed The code and tests address #3985 by making Bar use its own data when the chart lacks top-level data.
Out of Scope Changes check ✅ Passed The omnidoc snapshot updates are directly tied to the new Bar data prop support and are not out of scope.
Docstring Coverage ✅ Passed No functions found in the changed files to evaluate docstring coverage. Skipping docstring coverage check.
Title check ✅ Passed The title clearly states the main change: Bar now supports a direct data prop, matching other cartesian series.
Description check ✅ Passed The description includes summary, root cause, changes, related issues, and testing, covering the template's core sections.
✨ 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.

@codecov

codecov Bot commented Jul 29, 2026

Copy link
Copy Markdown

Bundle Report

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

Detailed changes
Bundle name Size Change
recharts/bundle-cjs 1.48MB -81 bytes (-0.01%) ⬇️
recharts/bundle-es6 1.31MB -81 bytes (-0.01%) ⬇️
recharts/bundle-treeshaking-cartesian 746.59kB -81 bytes (-0.01%) ⬇️

Affected Assets, Files, and Routes:

view changes for bundle: recharts/bundle-treeshaking-cartesian

Assets Changed:

Asset Name Size Change Total Size Change (%)
bundle.js -81 bytes 746.59kB -0.01%
view changes for bundle: recharts/bundle-cjs

Assets Changed:

Asset Name Size Change Total Size Change (%)
cartesian/Bar.js -81 bytes 33.62kB -0.24%
view changes for bundle: recharts/bundle-es6

Assets Changed:

Asset Name Size Change Total Size Change (%)
cartesian/Bar.js -81 bytes 31.88kB -0.25%

Bar now supports a data prop (previous commit), so the omnidoc
readProject snapshots need to include it in their prop lists.
@codecov

codecov Bot commented Jul 29, 2026

Copy link
Copy Markdown

Codecov Report

✅ All modified and coverable lines are covered by tests.
✅ Project coverage is 88.20%. Comparing base (187ff89) to head (37faf39).
⚠️ Report is 1 commits behind head on main.

Additional details and impacted files
@@           Coverage Diff           @@
##             main    #7599   +/-   ##
=======================================
  Coverage   88.19%   88.20%           
=======================================
  Files         620      620           
  Lines       14520    14520           
  Branches     3718     3717    -1     
=======================================
+ Hits        12806    12807    +1     
+ Misses       1519     1518    -1     
  Partials      195      195           

☔ View full report in Codecov by Harness.
📢 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.

@PavelVanecek
PavelVanecek merged commit 40878c5 into recharts:main Jul 30, 2026
58 checks passed
@PavelVanecek

Copy link
Copy Markdown
Collaborator

I'm going to handle this as a new feature

@PavelVanecek PavelVanecek changed the title fix(Bar): support data prop directly on Bar, like Line/Area/Scatter feat(Bar): support data prop directly on Bar, like Line/Area/Scatter Aug 23, 2026
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.

Bar doesn't render if top-level data isn't set

2 participants