Skip to content

Fix crash when Label is passed as content to LabelList#6732

Merged
ckifer merged 1 commit intorecharts:mainfrom
Harikrushn9118:fix/label-list-crash
Dec 3, 2025
Merged

Fix crash when Label is passed as content to LabelList#6732
ckifer merged 1 commit intorecharts:mainfrom
Harikrushn9118:fix/label-list-crash

Conversation

@Harikrushn9118
Copy link
Contributor

@Harikrushn9118 Harikrushn9118 commented Dec 3, 2025

Description

Fixed a stack overflow crash that occurred when <LabelList content={Label} /> was used. The crash was caused by LabelList passing the content prop (which was Label itself) back to the Label component, creating an infinite recursion loop where Label kept trying to render itself as its own content.

Fixes #6633

Changes

  • Modified src/component/Label.tsx to explicitly exclude the content prop from the props passed to the content function component.
  • This ensures that when Label renders a dynamic component (like itself), that component doesn't receive the content prop again, breaking the recursion cycle.

Verification

  • Added a reproduction test case in test/component/ReproduceCrash.spec.tsx (which I verified passes now).
  • Verified existing tests pass.

Summary by CodeRabbit

  • Bug Fixes
    • Fixed content function prop handling to eliminate unnecessary content property duplication when passing props to custom content components.

✏️ Tip: You can customize this high-level summary in your review settings.

@coderabbitai
Copy link
Contributor

coderabbitai bot commented Dec 3, 2025

Walkthrough

Removes the content prop from props passed to content components in the Label component to prevent crashes when using nested Label components. Updates corresponding test cases to reflect the changed prop shape.

Changes

Cohort / File(s) Summary
Label component fix
src/component/Label.tsx
Strips the content prop from props before passing to custom content components using destructuring, eliminating circular prop dependencies.
Label-related test updates
test/component/Label.spec.tsx, test/cartesian/Bar.spec.tsx
Removed content property from expected props passed to content functions to align with implementation change.

Estimated code review effort

🎯 2 (Simple) | ⏱️ ~8 minutes

  • Verify prop destructuring correctly filters only the content prop while preserving other props like viewBox, angle, offset, position, etc.
  • Confirm test expectations accurately reflect the new prop shape across all test cases
  • Check that nested Label components no longer cause crashes

Possibly related PRs

Suggested reviewers

  • ckifer

Pre-merge checks and finishing touches

❌ Failed checks (1 warning)
Check name Status Explanation Resolution
Docstring Coverage ⚠️ Warning Docstring coverage is 0.00% which is insufficient. The required threshold is 80.00%. You can run @coderabbitai generate docstrings to improve docstring coverage.
✅ Passed checks (4 passed)
Check name Status Explanation
Title check ✅ Passed The title accurately and concisely describes the main change: fixing a crash when Label is passed as content to LabelList.
Description check ✅ Passed The PR description covers the problem, solution, and verification but lacks detail on testing methodology and doesn't fully complete the template checklist.
Linked Issues check ✅ Passed The code changes directly address issue #6633 by removing the content prop from child components, preventing infinite recursion when Label is passed as content to LabelList.
Out of Scope Changes check ✅ Passed All changes are scoped to fixing the specific crash issue: Label.tsx fix, test updates in Bar.spec.tsx and Label.spec.tsx to reflect the prop removal.
✨ Finishing touches
  • 📝 Generate docstrings
🧪 Generate unit tests (beta)
  • Create PR with unit tests
  • Post copyable unit tests in a comment

📜 Recent review details

Configuration used: CodeRabbit UI

Review profile: CHILL

Plan: Pro

📥 Commits

Reviewing files that changed from the base of the PR and between c3bd1a0 and d106ba8.

📒 Files selected for processing (3)
  • src/component/Label.tsx (1 hunks)
  • test/cartesian/Bar.spec.tsx (0 hunks)
  • test/component/Label.spec.tsx (0 hunks)
💤 Files with no reviewable changes (2)
  • test/component/Label.spec.tsx
  • test/cartesian/Bar.spec.tsx
🧰 Additional context used
📓 Path-based instructions (4)
src/**/*.{js,jsx,ts,tsx}

📄 CodeRabbit inference engine (DEVELOPING.md)

Run ESLint and Prettier on the codebase using npm run lint

Files:

  • src/component/Label.tsx
**/*.{ts,tsx}

📄 CodeRabbit inference engine (DEVELOPING.md)

Run type checking on the codebase using npm run check-types

**/*.{ts,tsx}: Never use any type (implicit or explicit) in TypeScript code
Prefer unknown over any and refine the type in TypeScript
Type function parameters and return values explicitly in TypeScript, do not rely on implicit any or inference; exceptions are React components and trivial functions
Do not use as type assertions in TypeScript; the only exception is as const

Files:

  • src/component/Label.tsx
**/*.{js,ts,tsx}

📄 CodeRabbit inference engine (CONTRIBUTING.md)

Ensure code lints by running npm run lint and follows Airbnb's Style Guide

Files:

  • src/component/Label.tsx
src/**/*.{ts,tsx}

📄 CodeRabbit inference engine (AGENTS.md)

Do not hardcode any strings or formatting choices in library code; users should provide localized strings as desired

Files:

  • src/component/Label.tsx
🔇 Additional comments (1)
src/component/Label.tsx (1)

613-616: Fix correctly avoids recursive Labelcontent loops, with a small intentional API tweak

Stripping content out of propsWithViewBox before calling createElement cleanly prevents the infinite recursion when content={Label} while preserving all other props (including the resolved viewBox) for custom content components. This looks like the right minimal fix.

Note this does slightly change the runtime props shape for function content handlers: content is no longer present on props passed to the content function. Given content was previously the component itself (and a source of recursion risk), this trade‑off seems reasonable, but it is a (minor) behavioral change—worth confirming that tests and any docs/examples referring to props.content are updated as needed.

Also, please confirm npm run lint and npm run check-types pass with this change.


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.

@codecov
Copy link

codecov bot commented Dec 3, 2025

Codecov Report

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

Additional details and impacted files
@@           Coverage Diff           @@
##             main    #6732   +/-   ##
=======================================
  Coverage   94.02%   94.02%           
=======================================
  Files         500      500           
  Lines       42684    42685    +1     
  Branches     4917     4917           
=======================================
+ Hits        40135    40136    +1     
  Misses       2544     2544           
  Partials        5        5           

☔ 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 7c76cf3 into recharts:main Dec 3, 2025
33 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.

Page crashes when I pass Label as a content to LabelList

3 participants