Skip to content

Add generics to Bar#7015

Merged
ckifer merged 1 commit intomainfrom
bar-typed
Feb 17, 2026
Merged

Add generics to Bar#7015
ckifer merged 1 commit intomainfrom
bar-typed

Conversation

@PavelVanecek
Copy link
Collaborator

@PavelVanecek PavelVanecek commented Feb 16, 2026

Description

Same as #6993 but for Bar

Summary by CodeRabbit

  • Refactor

    • Bar component TypeScript typing enhanced with improved generic type parameter support, providing better type inference and validation.
  • Tests

    • Added extensive type safety test coverage for the Bar component across multiple data typing scenarios to ensure compile-time correctness.

@coderabbitai
Copy link
Contributor

coderabbitai bot commented Feb 16, 2026

Walkthrough

Updates Bar component's generic type parameters, replacing default-type BarProps with explicit (DataPointType, ValueAxisType) parameters, converts Props to a generic type alias, and changes Bar export from ComponentType to a generic callable form. Adds comprehensive TypeScript typing tests for Bar validating strong typing scenarios.

Changes

Cohort / File(s) Summary
Bar Component Type Updates
src/cartesian/Bar.tsx
Refactors BarProps to remove default generics, makes Props a generic type alias with explicit type parameters, changes Bar export signature from ComponentType to a generic callable form with memoization and displayName assignment.
Bar Typed Tests
test/cartesian/Bar/Bar.typed.spec.tsx
Introduces comprehensive TypeScript typing tests including explicit data type scenarios, string and function-based dataKey validation, type-checking assertions via ts-expect-error, and integration tests for getRelativeCoordinate with BarRectangleItem.
Area Test Reorganization
test/cartesian/Area.typed.spec.tsx
Relocates getRelativeCoordinate test block from "with all implicit types" context into a new top-level "event handlers" describe block; structural change only with no test logic modifications.

Estimated code review effort

🎯 3 (Moderate) | ⏱️ ~25 minutes

Possibly related PRs

Suggested reviewers

  • ckifer
🚥 Pre-merge checks | ✅ 3 | ❌ 1

❌ Failed checks (1 warning)

Check name Status Explanation Resolution
Description check ⚠️ Warning The description references a related PR but lacks required template sections like motivation, testing details, and change type classification. Complete the PR description using the template: add motivation/context, describe testing approach, specify change type (e.g., Breaking change), and mark relevant checklist items.
✅ Passed checks (3 passed)
Check name Status Explanation
Title check ✅ Passed The title clearly and concisely describes the main change: adding generic type parameters to the Bar component.
Docstring Coverage ✅ Passed No functions found in the changed files to evaluate docstring coverage. Skipping docstring coverage check.
Merge Conflict Detection ✅ Passed ✅ No merge conflicts detected when merging into main

✏️ 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
  • Commit unit tests in branch bar-typed

Tip

Issue Planner is now in beta. Read the docs and try it out! Share your feedback on Discord.


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.

Copy link
Contributor

@coderabbitai coderabbitai bot left a comment

Choose a reason for hiding this comment

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

🧹 Nitpick comments (2)
test/cartesian/Bar/Bar.typed.spec.tsx (2)

64-285: Missing vi.useFakeTimers() — tests that render via rechartsTestRender may be sensitive to timers.

The coding guidelines require vi.useFakeTimers() in all tests due to Redux autoBatchEnhancer dependency on timers. While isAnimationActive={false} likely mitigates animation-related timer issues, the autoBatchEnhancer dependency could still cause flaky behavior. Consider adding a beforeEach with vi.useFakeTimers().

That said, the existing Area.typed.spec.tsx follows the same pattern without fake timers and appears to work, so this may be a pre-existing gap rather than something introduced here.

Proposed fix
+import { beforeEach, describe, it, vi } from 'vitest';
-import { describe, it } from 'vitest';
 import { Bar, BarChart, BarRectangleItem, getRelativeCoordinate } from '../../../src';
 import { rechartsTestRender } from '../../helper/createSelectorTestCase';
 import { expectBars, ExpectedBar } from '../../helper/expectBars';
 
 ...
 
 describe('Bar with strong typing', () => {
+  beforeEach(() => {
+    vi.useFakeTimers();
+  });
+
   describe('with all implicit types', () => {

As per coding guidelines: "Use vi.useFakeTimers() in all tests due to Redux autoBatchEnhancer dependency on timers and requestAnimationFrame"


144-193: Consider converting commented-out tests to a TODO or tracked issue.

These commented-out blocks document expected behavior if Bar supported data prop directly. While the explanatory comments are helpful, large commented-out code blocks can become stale. An alternative would be to track this as a GitHub issue and reference it here with a brief // TODO: comment.

This is a minor nit — the comments are well-documented and the intent is clear.

@codecov
Copy link

codecov bot commented Feb 16, 2026

Codecov Report

✅ All modified and coverable lines are covered by tests.
✅ Project coverage is 90.11%. Comparing base (5e33c7b) to head (fb8f8fc).
⚠️ Report is 5 commits behind head on main.

Additional details and impacted files
@@           Coverage Diff           @@
##             main    #7015   +/-   ##
=======================================
  Coverage   90.11%   90.11%           
=======================================
  Files         524      524           
  Lines       39073    39073           
  Branches     5399     5399           
=======================================
  Hits        35211    35211           
  Misses       3853     3853           
  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.

@github-actions
Copy link
Contributor

Staging Deployment Details

These deployments will remain available for 30 days.

To update snapshots: Comment /update-snapshots on this PR to automatically update the baseline screenshots.

@codecov
Copy link

codecov bot commented Feb 16, 2026

Bundle Report

Changes will increase total bundle size by 148 bytes (0.01%) ⬆️. This is within the configured threshold ✅

Detailed changes
Bundle name Size Change
recharts/bundle-cjs 1.26MB 74 bytes (0.01%) ⬆️
recharts/bundle-es6 1.09MB 74 bytes (0.01%) ⬆️

Affected Assets, Files, and Routes:

view changes for bundle: recharts/bundle-es6

Assets Changed:

Asset Name Size Change Total Size Change (%)
cartesian/Bar.js 74 bytes 26.47kB 0.28%
view changes for bundle: recharts/bundle-cjs

Assets Changed:

Asset Name Size Change Total Size Change (%)
cartesian/Bar.js 74 bytes 28.22kB 0.26%

@ckifer ckifer merged commit c3b308c into main Feb 17, 2026
48 checks passed
@ckifer ckifer deleted the bar-typed branch February 17, 2026 18:27
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.

2 participants