Add graphicalItemId to tooltip payload object#6765
Conversation
WalkthroughThis pull request introduces a graphical item identification system to Recharts, replacing dataKey-based tracking with a unique graphicalItemId for each chart component. Components now support an optional Changes
Sequence DiagramsequenceDiagram
participant User as User Interaction
participant DOM as DOM Element
participant Middleware as Touch Event Middleware
participant Selector as Tooltip Selectors
participant Store as Redux Store
participant Tooltip as Tooltip Component
participant Payload as Tooltip Payload
User->>DOM: Touch/Mouse on Chart Item
DOM->>Middleware: Event triggered (graphicalItemId attribute)
Middleware->>DOM: Read graphicalItemId from element
Middleware->>Store: selectAllGraphicalItemsSettings(state)
Store-->>Middleware: Settings with matching graphicalItemId
Middleware->>Selector: selectTooltipCoordinate(state, tooltipIndex, graphicalItemId)
Selector->>Store: Query tooltipConfiguration by graphicalItemId
Store-->>Selector: Find matching configuration
Selector-->>Middleware: Return coordinate
Middleware->>Store: Dispatch activeMouseOverItemIndex with graphicalItemId
Store->>Tooltip: Update tooltip state
Tooltip->>Payload: Render with graphicalItemId in payload entries
Payload->>User: Display tooltip with item identification
Estimated code review effort🎯 4 (Complex) | ⏱️ ~50 minutes Areas requiring extra attention:
Possibly related PRs
Suggested labels
Suggested reviewers
Pre-merge checks and finishing touches❌ Failed checks (1 warning)
✅ Passed checks (2 passed)
✨ Finishing touches
🧪 Generate unit tests (beta)
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. Comment |
There was a problem hiding this comment.
Actionable comments posted: 1
Caution
Some comments are outside the diff and can’t be posted inline due to platform limitations.
⚠️ Outside diff range comments (2)
src/component/DefaultTooltipContent.tsx (1)
27-48: MakinggraphicalItemIdrequired is TypeScript-breaking; make it optional (or provide a compat path)
Payloadis exported, so changing it to requiregraphicalItemIdwill break consumers at compile time. SuggestgraphicalItemId?: string(and ensure internal payload construction always sets it).src/cartesian/Scatter.tsx (1)
414-428: Passidinto tooltip dispatch hooks so interactions carryactiveGraphicalItemId.
Right now hover/click dispatches don’t include the graphical item ID even though the hook supports it; this can reintroduce ambiguity when multiple scatters share adataKey.function ScatterSymbols(props: ScatterSymbolsProps) { const { points, allOtherScatterProps } = props; const { shape, activeShape, dataKey } = allOtherScatterProps; const activeIndex = useAppSelector(selectActiveTooltipIndex); + const { id, ...allOtherPropsWithoutId } = allOtherScatterProps; const { onMouseEnter: onMouseEnterFromProps, onClick: onItemClickFromProps, onMouseLeave: onMouseLeaveFromProps, ...restOfAllOtherProps } = allOtherScatterProps; - const onMouseEnterFromContext = useMouseEnterItemDispatch(onMouseEnterFromProps, dataKey); + const onMouseEnterFromContext = useMouseEnterItemDispatch(onMouseEnterFromProps, dataKey, id); const onMouseLeaveFromContext = useMouseLeaveItemDispatch(onMouseLeaveFromProps); - const onClickFromContext = useMouseClickItemDispatch(onItemClickFromProps, dataKey); + const onClickFromContext = useMouseClickItemDispatch(onItemClickFromProps, dataKey, id); if (!isNonEmptyArray(points)) { return null; } - const { id, ...allOtherPropsWithoutId } = allOtherScatterProps; const baseProps = svgPropertiesNoEvents(allOtherPropsWithoutId);
🧹 Nitpick comments (8)
src/state/touchEventsMiddleware.ts (1)
9-68: Avoid per-touch linear scan over all graphical items (and skip work when id missing)
This will run ontouchMove, soselectAllGraphicalItemsSettings(state).find(...)can become a hot path on busy charts. Consider a selector keyed bygraphicalItemId(e.g., an id→settings map) and early-return before searching whengraphicalItemIdis nullish.src/chart/SunburstChart.tsx (1)
247-276: Consider threading the resolvedidinto click/hover actions (activeGraphicalItemId) for parity with other charts.
This likely needs moving the event handlers into theRegisterGraphicalItemIdcallback (so they can captureid).Also applies to: 365-380
src/cartesian/Line.tsx (1)
68-120: Type alignment for internalidlooks correct, but consider usingGraphicalItemIdmore consistently across components.
InternalLineProps.id: GraphicalItemIdmatches the intent (unique graphical identity) and stays compatible sinceGraphicalItemIdis currently a string alias. IfGraphicalItemIdever becomes a branded type, this file will be “future-proof” while other components still usingstringmay become inconsistent.src/cartesian/Area.tsx (1)
1031-1051: Good: Area passes the registered id into tooltip settings (not the optional external prop).
Consider typing internalidasGraphicalItemId(likeLine.tsx) to keep the codebase consistent ifGraphicalItemIdever stops being a plainstring.src/chart/Sankey.tsx (1)
611-634: Consider addingidto the publicSankeyPropsinterface.The
idprop is now being used viaRegisterGraphicalItemId, but it's not explicitly declared in theSankeyPropsinterface. While it may work due to the SVGProps spread, explicitly addingid?: string;would improve discoverability and documentation for users who want to provide a custom ID.interface SankeyProps { nameKey?: DataKey<any>; dataKey?: DataKey<any>; width?: number | Percent; height?: number | Percent; data: SankeyData; nodePadding?: number; nodeWidth?: number; linkCurvature?: number; iterations?: number; // TODO object func node?: SankeyNodeOptions; link?: SankeyLinkOptions; style?: React.CSSProperties; className?: string; children?: ReactNode; margin?: Partial<Margin>; onClick?: (item: NodeProps | LinkProps, type: SankeyElementType, e: MouseEvent) => void; onMouseEnter?: (item: NodeProps | LinkProps, type: SankeyElementType, e: MouseEvent) => void; onMouseLeave?: (item: NodeProps | LinkProps, type: SankeyElementType, e: MouseEvent) => void; sort?: boolean; verticalAlign?: SankeyVerticalAlign; align?: 'left' | 'justify'; + id?: string; }test/helper/mockTouchingElement.ts (2)
1-3: Avoid importingTooltipIndexfrom internal slice in helpers unless necessary.If this helper is intended to be broadly reusable, consider taking
touchItemIndex: string(orstring | number) directly and keep Redux types out of DOM-mocking utilities. This reduces coupling tosrc/state/tooltipSlice.
18-22: ConvertsetAttributevalues to string (DOM API contract).
Element#setAttributetakes astringvalue; ifTooltipIndexever includes non-string values, TS/runtime drift is possible. Consider explicit coercion for both attributes:export function mockTouchingElement(touchItemIndex: NonNullable<TooltipIndex>, graphicalItemId: GraphicalItemId): void { const fakeElement = document.createElement('g'); - fakeElement.setAttribute(DATA_ITEM_INDEX_ATTRIBUTE_NAME, touchItemIndex); - fakeElement.setAttribute(DATA_ITEM_GRAPHICAL_ITEM_ID_ATTRIBUTE_NAME, graphicalItemId); + fakeElement.setAttribute(DATA_ITEM_INDEX_ATTRIBUTE_NAME, String(touchItemIndex)); + fakeElement.setAttribute(DATA_ITEM_GRAPHICAL_ITEM_ID_ATTRIBUTE_NAME, String(graphicalItemId)); document.elementFromPoint = () => fakeElement; }src/chart/Treemap.tsx (1)
693-698: Good: internalidis a resolvedGraphicalItemIdviaRegisterGraphicalItemId.One small readability tweak: consider
{ id: externalId, ...rest } = propsto avoid passingidtwice (even though the explicitid={id}correctly wins).Also applies to: 942-955
📜 Review details
Configuration used: CodeRabbit UI
Review profile: CHILL
Plan: Pro
📒 Files selected for processing (36)
omnidoc/readProject.spec.ts(1 hunks)src/cartesian/Area.tsx(3 hunks)src/cartesian/Bar.tsx(5 hunks)src/cartesian/Funnel.tsx(16 hunks)src/cartesian/Line.tsx(5 hunks)src/cartesian/Scatter.tsx(7 hunks)src/chart/Sankey.tsx(6 hunks)src/chart/SunburstChart.tsx(6 hunks)src/chart/Treemap.tsx(7 hunks)src/component/DefaultTooltipContent.tsx(1 hunks)src/polar/Pie.tsx(7 hunks)src/polar/Radar.tsx(3 hunks)src/polar/RadialBar.tsx(2 hunks)src/state/selectors/funnelSelectors.ts(4 hunks)src/state/selectors/touchSelectors.ts(1 hunks)src/state/touchEventsMiddleware.ts(2 hunks)src/util/Constants.ts(1 hunks)test/cartesian/Area.spec.tsx(4 hunks)test/cartesian/Bar.spec.tsx(4 hunks)test/cartesian/Line.spec.tsx(1 hunks)test/cartesian/Scatter.spec.tsx(2 hunks)test/chart/LineChart.spec.tsx(2 hunks)test/chart/ScatterChart.spec.tsx(11 hunks)test/chart/Treemap.spec.tsx(3 hunks)test/component/Cursor.spec.tsx(2 hunks)test/component/DefaultTooltipContent.spec.tsx(2 hunks)test/component/Tooltip/Tooltip.content.spec.tsx(6 hunks)test/component/Tooltip/Tooltip.formatter.spec.tsx(6 hunks)test/component/Tooltip/Tooltip.payload.spec.tsx(13 hunks)test/component/Tooltip/Tooltip.visibility.spec.tsx(17 hunks)test/component/Tooltip/defaultIndex.spec.tsx(8 hunks)test/component/Tooltip/itemSorter.spec.tsx(81 hunks)test/helper/mockTouchingElement.ts(2 hunks)test/polar/Pie.spec.tsx(33 hunks)test/state/selectors/pieSelectors.spec.tsx(16 hunks)test/state/selectors/selectors.spec.tsx(20 hunks)
🧰 Additional context used
📓 Path-based instructions (8)
**/*.{ts,tsx}
📄 CodeRabbit inference engine (CONTRIBUTING.md)
**/*.{ts,tsx}: Never useanytype (implicit or explicit) in TypeScript code
Preferunknownoveranyand 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 useastype assertions in TypeScript; the only exception isas const
Files:
test/cartesian/Bar.spec.tsxomnidoc/readProject.spec.tstest/helper/mockTouchingElement.tssrc/state/touchEventsMiddleware.tstest/chart/ScatterChart.spec.tsxtest/component/Tooltip/defaultIndex.spec.tsxsrc/polar/Pie.tsxtest/chart/Treemap.spec.tsxsrc/util/Constants.tssrc/cartesian/Area.tsxtest/component/Tooltip/Tooltip.formatter.spec.tsxtest/cartesian/Scatter.spec.tsxtest/component/Cursor.spec.tsxsrc/chart/SunburstChart.tsxtest/cartesian/Line.spec.tsxsrc/polar/RadialBar.tsxsrc/component/DefaultTooltipContent.tsxsrc/state/selectors/funnelSelectors.tssrc/cartesian/Bar.tsxtest/chart/LineChart.spec.tsxtest/state/selectors/selectors.spec.tsxsrc/polar/Radar.tsxsrc/cartesian/Scatter.tsxsrc/chart/Treemap.tsxtest/component/Tooltip/Tooltip.payload.spec.tsxtest/component/DefaultTooltipContent.spec.tsxtest/polar/Pie.spec.tsxsrc/state/selectors/touchSelectors.tssrc/cartesian/Funnel.tsxsrc/chart/Sankey.tsxtest/component/Tooltip/itemSorter.spec.tsxsrc/cartesian/Line.tsxtest/component/Tooltip/Tooltip.visibility.spec.tsxtest/state/selectors/pieSelectors.spec.tsxtest/component/Tooltip/Tooltip.content.spec.tsxtest/cartesian/Area.spec.tsx
test/**/*.spec.{ts,tsx}
📄 CodeRabbit inference engine (CONTRIBUTING.md)
Aim for 100% unit test code coverage when writing new code
Files:
test/cartesian/Bar.spec.tsxtest/chart/ScatterChart.spec.tsxtest/component/Tooltip/defaultIndex.spec.tsxtest/chart/Treemap.spec.tsxtest/component/Tooltip/Tooltip.formatter.spec.tsxtest/cartesian/Scatter.spec.tsxtest/component/Cursor.spec.tsxtest/cartesian/Line.spec.tsxtest/chart/LineChart.spec.tsxtest/state/selectors/selectors.spec.tsxtest/component/Tooltip/Tooltip.payload.spec.tsxtest/component/DefaultTooltipContent.spec.tsxtest/polar/Pie.spec.tsxtest/component/Tooltip/itemSorter.spec.tsxtest/component/Tooltip/Tooltip.visibility.spec.tsxtest/state/selectors/pieSelectors.spec.tsxtest/component/Tooltip/Tooltip.content.spec.tsxtest/cartesian/Area.spec.tsx
**/*.{js,ts,tsx}
📄 CodeRabbit inference engine (CONTRIBUTING.md)
Ensure code lints by running
npm run lintand follows Airbnb's Style Guide
Files:
test/cartesian/Bar.spec.tsxomnidoc/readProject.spec.tstest/helper/mockTouchingElement.tssrc/state/touchEventsMiddleware.tstest/chart/ScatterChart.spec.tsxtest/component/Tooltip/defaultIndex.spec.tsxsrc/polar/Pie.tsxtest/chart/Treemap.spec.tsxsrc/util/Constants.tssrc/cartesian/Area.tsxtest/component/Tooltip/Tooltip.formatter.spec.tsxtest/cartesian/Scatter.spec.tsxtest/component/Cursor.spec.tsxsrc/chart/SunburstChart.tsxtest/cartesian/Line.spec.tsxsrc/polar/RadialBar.tsxsrc/component/DefaultTooltipContent.tsxsrc/state/selectors/funnelSelectors.tssrc/cartesian/Bar.tsxtest/chart/LineChart.spec.tsxtest/state/selectors/selectors.spec.tsxsrc/polar/Radar.tsxsrc/cartesian/Scatter.tsxsrc/chart/Treemap.tsxtest/component/Tooltip/Tooltip.payload.spec.tsxtest/component/DefaultTooltipContent.spec.tsxtest/polar/Pie.spec.tsxsrc/state/selectors/touchSelectors.tssrc/cartesian/Funnel.tsxsrc/chart/Sankey.tsxtest/component/Tooltip/itemSorter.spec.tsxsrc/cartesian/Line.tsxtest/component/Tooltip/Tooltip.visibility.spec.tsxtest/state/selectors/pieSelectors.spec.tsxtest/component/Tooltip/Tooltip.content.spec.tsxtest/cartesian/Area.spec.tsx
test/**/*.{test,spec}.{ts,tsx}
📄 CodeRabbit inference engine (test/README.md)
test/**/*.{test,spec}.{ts,tsx}: Aim for 100% unit test code coverage when writing new code
Prefer to use thecreateSelectorTestCasehelper function when writing or modifying tests
Use theexpectLastCalledWithhelper function instead ofexpect(spy).toHaveBeenLastCalledWith(...)for better typing and autocompletion
Verify the number of selector calls using the spy object fromcreateSelectorTestCaseto spot unnecessary re-renders and improve performance
MockgetBoundingClientRectin tests using the helper function provided intest/helper/MockGetBoundingClientRect.ts
Usevi.useFakeTimers()in all tests due to Redux autoBatchEnhancer dependency on timers andrequestAnimationFrame
Callvi.runOnlyPendingTimers()to advance timers after renders when not usingcreateSelectorTestCasehelper, and avoidvi.runAllTimers()to prevent infinite loops
UseuserEvent.setup({ advanceTimers: vi.runOnlyPendingTimers })or theuserEventSetuphelper function fromtest/helper/userEventSetup.tswhen creating userEvent instances
When testing tooltips on hover, usevi.runOnlyPendingTimers()after eachuserEvent.hover()call or use theshowTooltiphelper function fromtooltipTestHelpers.tsto account for requestAnimationFrame delays
Files:
test/cartesian/Bar.spec.tsxtest/chart/ScatterChart.spec.tsxtest/component/Tooltip/defaultIndex.spec.tsxtest/chart/Treemap.spec.tsxtest/component/Tooltip/Tooltip.formatter.spec.tsxtest/cartesian/Scatter.spec.tsxtest/component/Cursor.spec.tsxtest/cartesian/Line.spec.tsxtest/chart/LineChart.spec.tsxtest/state/selectors/selectors.spec.tsxtest/component/Tooltip/Tooltip.payload.spec.tsxtest/component/DefaultTooltipContent.spec.tsxtest/polar/Pie.spec.tsxtest/component/Tooltip/itemSorter.spec.tsxtest/component/Tooltip/Tooltip.visibility.spec.tsxtest/state/selectors/pieSelectors.spec.tsxtest/component/Tooltip/Tooltip.content.spec.tsxtest/cartesian/Area.spec.tsx
**/*.spec.{ts,tsx}
📄 CodeRabbit inference engine (AGENTS.md)
When running unit tests, prefer to run a single test file using
npm run test -- path/to/TestFile.spec.tsxrather than running all tests withnpm test
Files:
test/cartesian/Bar.spec.tsxomnidoc/readProject.spec.tstest/chart/ScatterChart.spec.tsxtest/component/Tooltip/defaultIndex.spec.tsxtest/chart/Treemap.spec.tsxtest/component/Tooltip/Tooltip.formatter.spec.tsxtest/cartesian/Scatter.spec.tsxtest/component/Cursor.spec.tsxtest/cartesian/Line.spec.tsxtest/chart/LineChart.spec.tsxtest/state/selectors/selectors.spec.tsxtest/component/Tooltip/Tooltip.payload.spec.tsxtest/component/DefaultTooltipContent.spec.tsxtest/polar/Pie.spec.tsxtest/component/Tooltip/itemSorter.spec.tsxtest/component/Tooltip/Tooltip.visibility.spec.tsxtest/state/selectors/pieSelectors.spec.tsxtest/component/Tooltip/Tooltip.content.spec.tsxtest/cartesian/Area.spec.tsx
**/*.{ts,tsx,js,jsx}
📄 CodeRabbit inference engine (DEVELOPING.md)
All imports from
rechartsmust use the public API entry point; imports from internal paths likerecharts/types/*orrecharts/src/*are not allowed
Files:
test/cartesian/Bar.spec.tsxomnidoc/readProject.spec.tstest/helper/mockTouchingElement.tssrc/state/touchEventsMiddleware.tstest/chart/ScatterChart.spec.tsxtest/component/Tooltip/defaultIndex.spec.tsxsrc/polar/Pie.tsxtest/chart/Treemap.spec.tsxsrc/util/Constants.tssrc/cartesian/Area.tsxtest/component/Tooltip/Tooltip.formatter.spec.tsxtest/cartesian/Scatter.spec.tsxtest/component/Cursor.spec.tsxsrc/chart/SunburstChart.tsxtest/cartesian/Line.spec.tsxsrc/polar/RadialBar.tsxsrc/component/DefaultTooltipContent.tsxsrc/state/selectors/funnelSelectors.tssrc/cartesian/Bar.tsxtest/chart/LineChart.spec.tsxtest/state/selectors/selectors.spec.tsxsrc/polar/Radar.tsxsrc/cartesian/Scatter.tsxsrc/chart/Treemap.tsxtest/component/Tooltip/Tooltip.payload.spec.tsxtest/component/DefaultTooltipContent.spec.tsxtest/polar/Pie.spec.tsxsrc/state/selectors/touchSelectors.tssrc/cartesian/Funnel.tsxsrc/chart/Sankey.tsxtest/component/Tooltip/itemSorter.spec.tsxsrc/cartesian/Line.tsxtest/component/Tooltip/Tooltip.visibility.spec.tsxtest/state/selectors/pieSelectors.spec.tsxtest/component/Tooltip/Tooltip.content.spec.tsxtest/cartesian/Area.spec.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/state/touchEventsMiddleware.tssrc/polar/Pie.tsxsrc/util/Constants.tssrc/cartesian/Area.tsxsrc/chart/SunburstChart.tsxsrc/polar/RadialBar.tsxsrc/component/DefaultTooltipContent.tsxsrc/state/selectors/funnelSelectors.tssrc/cartesian/Bar.tsxsrc/polar/Radar.tsxsrc/cartesian/Scatter.tsxsrc/chart/Treemap.tsxsrc/state/selectors/touchSelectors.tssrc/cartesian/Funnel.tsxsrc/chart/Sankey.tsxsrc/cartesian/Line.tsx
test/component/**/*.spec.tsx
📄 CodeRabbit inference engine (CONTRIBUTING.md)
Use React Testing Library for testing component interactions and behavior upon rendering
Files:
test/component/Tooltip/defaultIndex.spec.tsxtest/component/Tooltip/Tooltip.formatter.spec.tsxtest/component/Cursor.spec.tsxtest/component/Tooltip/Tooltip.payload.spec.tsxtest/component/DefaultTooltipContent.spec.tsxtest/component/Tooltip/itemSorter.spec.tsxtest/component/Tooltip/Tooltip.visibility.spec.tsxtest/component/Tooltip/Tooltip.content.spec.tsx
🧠 Learnings (15)
📓 Common learnings
Learnt from: PavelVanecek
Repo: recharts/recharts PR: 6669
File: www/src/docs/exampleComponents/ScatterChart/ScatterChartWithLabels.tsx:2-2
Timestamp: 2025-11-23T13:30:10.395Z
Learning: The `TooltipIndex` type from recharts is defined in `src/state/tooltipSlice.ts` but is not currently exported from the public API entry points. It should not be imported from `recharts/types/state/tooltipSlice` as this is an internal implementation path. An ESLint rule is needed to prevent regressions.
Learnt from: PavelVanecek
Repo: recharts/recharts PR: 6659
File: www/src/components/GuideView/Performance/index.tsx:232-250
Timestamp: 2025-11-19T14:08:01.728Z
Learning: In Recharts version 3.4.2, object-as-prop optimizations were introduced to reduce unnecessary re-renders when new object references are passed as props. This affects the recommendation for the `react-perf/jsx-no-new-object-as-prop` ESLint rule.
📚 Learning: 2025-11-23T13:30:10.395Z
Learnt from: PavelVanecek
Repo: recharts/recharts PR: 6669
File: www/src/docs/exampleComponents/ScatterChart/ScatterChartWithLabels.tsx:2-2
Timestamp: 2025-11-23T13:30:10.395Z
Learning: The `TooltipIndex` type from recharts is defined in `src/state/tooltipSlice.ts` but is not currently exported from the public API entry points. It should not be imported from `recharts/types/state/tooltipSlice` as this is an internal implementation path. An ESLint rule is needed to prevent regressions.
Applied to files:
test/cartesian/Bar.spec.tsxtest/helper/mockTouchingElement.tssrc/state/touchEventsMiddleware.tstest/chart/ScatterChart.spec.tsxtest/component/Tooltip/defaultIndex.spec.tsxsrc/polar/Pie.tsxtest/chart/Treemap.spec.tsxsrc/util/Constants.tssrc/cartesian/Area.tsxtest/component/Tooltip/Tooltip.formatter.spec.tsxtest/cartesian/Scatter.spec.tsxtest/component/Cursor.spec.tsxsrc/chart/SunburstChart.tsxtest/cartesian/Line.spec.tsxsrc/polar/RadialBar.tsxsrc/component/DefaultTooltipContent.tsxsrc/state/selectors/funnelSelectors.tssrc/cartesian/Bar.tsxtest/chart/LineChart.spec.tsxtest/state/selectors/selectors.spec.tsxsrc/polar/Radar.tsxsrc/chart/Treemap.tsxtest/component/Tooltip/Tooltip.payload.spec.tsxtest/component/DefaultTooltipContent.spec.tsxtest/polar/Pie.spec.tsxsrc/state/selectors/touchSelectors.tssrc/cartesian/Funnel.tsxsrc/chart/Sankey.tsxtest/component/Tooltip/itemSorter.spec.tsxsrc/cartesian/Line.tsxtest/component/Tooltip/Tooltip.visibility.spec.tsxtest/state/selectors/pieSelectors.spec.tsxtest/component/Tooltip/Tooltip.content.spec.tsxtest/cartesian/Area.spec.tsx
📚 Learning: 2025-11-25T01:23:08.250Z
Learnt from: CR
Repo: recharts/recharts PR: 0
File: test/README.md:0-0
Timestamp: 2025-11-25T01:23:08.250Z
Learning: Applies to test/**/*.{test,spec}.{ts,tsx} : When testing tooltips on hover, use `vi.runOnlyPendingTimers()` after each `userEvent.hover()` call or use the `showTooltip` helper function from `tooltipTestHelpers.ts` to account for requestAnimationFrame delays
Applied to files:
test/cartesian/Bar.spec.tsxtest/helper/mockTouchingElement.tstest/chart/ScatterChart.spec.tsxtest/component/Tooltip/defaultIndex.spec.tsxtest/component/Tooltip/Tooltip.formatter.spec.tsxtest/cartesian/Scatter.spec.tsxtest/component/Cursor.spec.tsxtest/cartesian/Line.spec.tsxtest/chart/LineChart.spec.tsxtest/state/selectors/selectors.spec.tsxtest/component/Tooltip/Tooltip.payload.spec.tsxtest/component/DefaultTooltipContent.spec.tsxtest/polar/Pie.spec.tsxtest/component/Tooltip/itemSorter.spec.tsxtest/component/Tooltip/Tooltip.visibility.spec.tsxtest/state/selectors/pieSelectors.spec.tsxtest/component/Tooltip/Tooltip.content.spec.tsxtest/cartesian/Area.spec.tsx
📚 Learning: 2025-11-25T01:23:08.250Z
Learnt from: CR
Repo: recharts/recharts PR: 0
File: test/README.md:0-0
Timestamp: 2025-11-25T01:23:08.250Z
Learning: Applies to test/**/*.{test,spec}.{ts,tsx} : Verify the number of selector calls using the spy object from `createSelectorTestCase` to spot unnecessary re-renders and improve performance
Applied to files:
test/cartesian/Bar.spec.tsxomnidoc/readProject.spec.tstest/chart/ScatterChart.spec.tsxtest/component/Tooltip/defaultIndex.spec.tsxtest/chart/Treemap.spec.tsxtest/component/Tooltip/Tooltip.formatter.spec.tsxtest/cartesian/Scatter.spec.tsxtest/cartesian/Line.spec.tsxtest/chart/LineChart.spec.tsxtest/state/selectors/selectors.spec.tsxtest/component/DefaultTooltipContent.spec.tsxtest/polar/Pie.spec.tsxsrc/state/selectors/touchSelectors.tstest/component/Tooltip/itemSorter.spec.tsxtest/component/Tooltip/Tooltip.visibility.spec.tsxtest/state/selectors/pieSelectors.spec.tsxtest/component/Tooltip/Tooltip.content.spec.tsxtest/cartesian/Area.spec.tsx
📚 Learning: 2025-11-25T01:23:08.250Z
Learnt from: CR
Repo: recharts/recharts PR: 0
File: test/README.md:0-0
Timestamp: 2025-11-25T01:23:08.250Z
Learning: Applies to test/**/*.{test,spec}.{ts,tsx} : Use the `expectLastCalledWith` helper function instead of `expect(spy).toHaveBeenLastCalledWith(...)` for better typing and autocompletion
Applied to files:
test/cartesian/Bar.spec.tsxtest/chart/Treemap.spec.tsxtest/cartesian/Line.spec.tsxtest/polar/Pie.spec.tsxtest/component/Tooltip/itemSorter.spec.tsxtest/component/Tooltip/Tooltip.visibility.spec.tsxtest/component/Tooltip/Tooltip.content.spec.tsxtest/cartesian/Area.spec.tsx
📚 Learning: 2025-11-19T14:08:01.728Z
Learnt from: PavelVanecek
Repo: recharts/recharts PR: 6659
File: www/src/components/GuideView/Performance/index.tsx:232-250
Timestamp: 2025-11-19T14:08:01.728Z
Learning: In Recharts version 3.4.2, object-as-prop optimizations were introduced to reduce unnecessary re-renders when new object references are passed as props. This affects the recommendation for the `react-perf/jsx-no-new-object-as-prop` ESLint rule.
Applied to files:
test/cartesian/Bar.spec.tsxsrc/chart/SunburstChart.tsxtest/cartesian/Line.spec.tsx
📚 Learning: 2025-11-25T01:23:08.250Z
Learnt from: CR
Repo: recharts/recharts PR: 0
File: test/README.md:0-0
Timestamp: 2025-11-25T01:23:08.250Z
Learning: Applies to test/**/*.{test,spec}.{ts,tsx} : Mock `getBoundingClientRect` in tests using the helper function provided in `test/helper/MockGetBoundingClientRect.ts`
Applied to files:
test/helper/mockTouchingElement.tstest/component/DefaultTooltipContent.spec.tsxtest/polar/Pie.spec.tsxtest/component/Tooltip/Tooltip.visibility.spec.tsxtest/component/Tooltip/Tooltip.content.spec.tsxtest/cartesian/Area.spec.tsx
📚 Learning: 2025-11-25T01:23:08.250Z
Learnt from: CR
Repo: recharts/recharts PR: 0
File: test/README.md:0-0
Timestamp: 2025-11-25T01:23:08.250Z
Learning: Applies to test/**/*.{test,spec}.{ts,tsx} : Prefer to use the `createSelectorTestCase` helper function when writing or modifying tests
Applied to files:
test/chart/ScatterChart.spec.tsxtest/component/Tooltip/defaultIndex.spec.tsxtest/chart/LineChart.spec.tsxtest/polar/Pie.spec.tsxtest/component/Tooltip/itemSorter.spec.tsxtest/component/Tooltip/Tooltip.visibility.spec.tsxtest/component/Tooltip/Tooltip.content.spec.tsxtest/cartesian/Area.spec.tsx
📚 Learning: 2025-11-25T01:22:59.729Z
Learnt from: CR
Repo: recharts/recharts PR: 0
File: CONTRIBUTING.md:0-0
Timestamp: 2025-11-25T01:22:59.729Z
Learning: Applies to test/component/**/*.spec.tsx : Use React Testing Library for testing component interactions and behavior upon rendering
Applied to files:
test/component/Tooltip/defaultIndex.spec.tsxtest/chart/Treemap.spec.tsxtest/cartesian/Line.spec.tsxtest/chart/LineChart.spec.tsxtest/component/DefaultTooltipContent.spec.tsxtest/polar/Pie.spec.tsxtest/component/Tooltip/itemSorter.spec.tsxtest/component/Tooltip/Tooltip.visibility.spec.tsxtest/component/Tooltip/Tooltip.content.spec.tsxtest/cartesian/Area.spec.tsx
📚 Learning: 2025-11-25T01:23:08.250Z
Learnt from: CR
Repo: recharts/recharts PR: 0
File: test/README.md:0-0
Timestamp: 2025-11-25T01:23:08.250Z
Learning: Applies to test/**/*.{test,spec}.{ts,tsx} : Call `vi.runOnlyPendingTimers()` to advance timers after renders when not using `createSelectorTestCase` helper, and avoid `vi.runAllTimers()` to prevent infinite loops
Applied to files:
test/component/Tooltip/defaultIndex.spec.tsxtest/chart/LineChart.spec.tsxtest/polar/Pie.spec.tsxtest/component/Tooltip/Tooltip.visibility.spec.tsxtest/component/Tooltip/Tooltip.content.spec.tsxtest/cartesian/Area.spec.tsx
📚 Learning: 2025-12-06T03:36:59.377Z
Learnt from: CR
Repo: recharts/recharts PR: 0
File: DEVELOPING.md:0-0
Timestamp: 2025-12-06T03:36:59.377Z
Learning: Applies to **/*.{ts,tsx,js,jsx} : All imports from `recharts` must use the public API entry point; imports from internal paths like `recharts/types/*` or `recharts/src/*` are not allowed
Applied to files:
test/chart/Treemap.spec.tsxsrc/util/Constants.tssrc/chart/SunburstChart.tsxtest/polar/Pie.spec.tsxtest/cartesian/Area.spec.tsx
📚 Learning: 2025-12-08T08:23:26.219Z
Learnt from: PavelVanecek
Repo: recharts/recharts PR: 6750
File: src/state/selectors/axisSelectors.ts:593-602
Timestamp: 2025-12-08T08:23:26.219Z
Learning: In the recharts codebase, `DataKey<any>` is an intentional exception to the "no any" rule while proper typing is being developed. This should not be flagged in reviews.
Applied to files:
src/util/Constants.tstest/cartesian/Line.spec.tsx
📚 Learning: 2025-11-25T01:23:08.250Z
Learnt from: CR
Repo: recharts/recharts PR: 0
File: test/README.md:0-0
Timestamp: 2025-11-25T01:23:08.250Z
Learning: Applies to test/**/*.{test,spec}.{ts,tsx} : Use `vi.useFakeTimers()` in all tests due to Redux autoBatchEnhancer dependency on timers and `requestAnimationFrame`
Applied to files:
test/polar/Pie.spec.tsxtest/component/Tooltip/Tooltip.content.spec.tsxtest/cartesian/Area.spec.tsx
📚 Learning: 2025-11-25T01:22:59.729Z
Learnt from: CR
Repo: recharts/recharts PR: 0
File: CONTRIBUTING.md:0-0
Timestamp: 2025-11-25T01:22:59.729Z
Learning: Applies to storybook/stories/**/*.stories.tsx : Use Storybook for smoke tests and add play functions with assertions for actual tests
Applied to files:
test/polar/Pie.spec.tsxtest/component/Tooltip/Tooltip.content.spec.tsxtest/cartesian/Area.spec.tsx
📚 Learning: 2025-11-25T01:23:08.250Z
Learnt from: CR
Repo: recharts/recharts PR: 0
File: test/README.md:0-0
Timestamp: 2025-11-25T01:23:08.250Z
Learning: Applies to test/**/*.{test,spec}.{ts,tsx} : Use `userEvent.setup({ advanceTimers: vi.runOnlyPendingTimers })` or the `userEventSetup` helper function from `test/helper/userEventSetup.ts` when creating userEvent instances
Applied to files:
test/polar/Pie.spec.tsx
🧬 Code graph analysis (26)
test/helper/mockTouchingElement.ts (2)
src/state/graphicalItemsSlice.ts (1)
GraphicalItemId(19-19)src/util/Constants.ts (2)
DATA_ITEM_INDEX_ATTRIBUTE_NAME(33-33)DATA_ITEM_GRAPHICAL_ITEM_ID_ATTRIBUTE_NAME(39-39)
src/state/touchEventsMiddleware.ts (3)
src/util/Constants.ts (1)
DATA_ITEM_GRAPHICAL_ITEM_ID_ATTRIBUTE_NAME(39-39)src/state/selectors/tooltipSelectors.ts (1)
selectAllGraphicalItemsSettings(110-119)src/state/selectors/touchSelectors.ts (1)
selectTooltipCoordinate(12-44)
test/chart/ScatterChart.spec.tsx (2)
src/cartesian/Scatter.tsx (1)
Scatter(818-818)src/index.ts (1)
Scatter(89-89)
test/component/Tooltip/defaultIndex.spec.tsx (3)
src/cartesian/Bar.tsx (1)
Bar(1085-1085)src/cartesian/Line.tsx (1)
Line(873-873)src/polar/Pie.tsx (1)
Pie(894-934)
src/polar/Pie.tsx (2)
src/index.ts (1)
PieSectorDataItem(61-61)src/util/Constants.ts (1)
DATA_ITEM_GRAPHICAL_ITEM_ID_ATTRIBUTE_NAME(39-39)
src/cartesian/Area.tsx (1)
src/util/useUniqueId.ts (1)
WithIdRequired(33-35)
test/component/Tooltip/Tooltip.formatter.spec.tsx (1)
src/cartesian/Bar.tsx (1)
Bar(1085-1085)
test/component/Cursor.spec.tsx (1)
src/state/tooltipSlice.ts (1)
TooltipPayload(29-29)
src/chart/SunburstChart.tsx (2)
src/util/useUniqueId.ts (1)
WithIdRequired(33-35)src/context/RegisterGraphicalItemId.tsx (1)
RegisterGraphicalItemId(18-21)
src/polar/RadialBar.tsx (2)
src/util/useUniqueId.ts (1)
WithIdRequired(33-35)src/state/tooltipSlice.ts (1)
TooltipPayloadConfiguration(52-69)
src/state/selectors/funnelSelectors.ts (4)
src/state/graphicalItemsSlice.ts (1)
GraphicalItemId(19-19)src/cartesian/Funnel.tsx (1)
FunnelTrapezoidItem(52-62)src/state/selectors/dataSelectors.ts (1)
selectChartDataAndAlwaysIgnoreIndexes(24-35)src/util/types.ts (1)
ChartOffsetInternal(643-651)
src/cartesian/Bar.tsx (1)
src/state/graphicalItemsSlice.ts (1)
GraphicalItemId(19-19)
test/chart/LineChart.spec.tsx (2)
src/cartesian/Line.tsx (1)
Line(873-873)src/index.ts (1)
Line(81-81)
test/state/selectors/selectors.spec.tsx (3)
src/state/tooltipSlice.ts (2)
TooltipPayloadEntry(11-11)TooltipPayloadConfiguration(52-69)src/polar/Pie.tsx (1)
Pie(894-934)src/index.ts (1)
Pie(56-56)
src/polar/Radar.tsx (1)
src/util/useUniqueId.ts (1)
WithIdRequired(33-35)
src/cartesian/Scatter.tsx (3)
src/state/graphicalItemsSlice.ts (1)
GraphicalItemId(19-19)src/context/tooltipContext.tsx (3)
useMouseEnterItemDispatch(21-38)useMouseLeaveItemDispatch(40-48)useMouseClickItemDispatch(50-67)src/util/Constants.ts (1)
DATA_ITEM_GRAPHICAL_ITEM_ID_ATTRIBUTE_NAME(39-39)
src/chart/Treemap.tsx (2)
src/state/graphicalItemsSlice.ts (1)
GraphicalItemId(19-19)src/context/RegisterGraphicalItemId.tsx (1)
RegisterGraphicalItemId(18-21)
test/component/Tooltip/Tooltip.payload.spec.tsx (2)
src/cartesian/Line.tsx (1)
Line(873-873)test/_data.ts (1)
PageData(4-11)
test/polar/Pie.spec.tsx (3)
src/util/Constants.ts (2)
DATA_ITEM_GRAPHICAL_ITEM_ID_ATTRIBUTE_NAME(39-39)DATA_ITEM_INDEX_ATTRIBUTE_NAME(33-33)src/polar/Pie.tsx (2)
PieSectorDataItem(157-161)Pie(894-934)test/helper/mockTouchingElement.ts (1)
mockTouchingElement(18-23)
src/state/selectors/touchSelectors.ts (5)
src/state/tooltipSlice.ts (2)
TooltipPayloadConfiguration(52-69)TooltipPayloadSearcher(45-50)src/state/selectors/selectTooltipState.ts (1)
selectTooltipState(4-4)src/state/graphicalItemsSlice.ts (1)
GraphicalItemId(19-19)src/util/types.ts (1)
Coordinate(88-91)src/state/selectors/selectTooltipPayloadSearcher.ts (1)
selectTooltipPayloadSearcher(4-5)
src/chart/Sankey.tsx (4)
src/util/useUniqueId.ts (1)
WithIdRequired(33-35)src/state/RechartsStoreProvider.tsx (1)
RechartsStoreProvider(15-53)src/context/chartLayoutContext.tsx (2)
ReportChartSize(165-208)ReportChartMargin(210-216)src/context/RegisterGraphicalItemId.tsx (1)
RegisterGraphicalItemId(18-21)
test/component/Tooltip/itemSorter.spec.tsx (8)
src/cartesian/Area.tsx (1)
Area(1074-1074)src/cartesian/Bar.tsx (1)
Bar(1085-1085)src/cartesian/Line.tsx (1)
Line(873-873)src/cartesian/Scatter.tsx (1)
Scatter(818-818)src/polar/Pie.tsx (1)
Pie(894-934)test/_data.ts (1)
PageData(4-11)src/polar/Radar.tsx (1)
Radar(571-602)src/polar/RadialBar.tsx (1)
RadialBar(646-671)
src/cartesian/Line.tsx (1)
src/state/graphicalItemsSlice.ts (1)
GraphicalItemId(19-19)
test/component/Tooltip/Tooltip.visibility.spec.tsx (4)
src/polar/Pie.tsx (1)
Pie(894-934)src/polar/Radar.tsx (1)
Radar(571-602)src/polar/RadialBar.tsx (1)
RadialBar(646-671)test/helper/mockTouchingElement.ts (1)
mockTouchingElement(18-23)
test/component/Tooltip/Tooltip.content.spec.tsx (2)
src/component/Tooltip.tsx (1)
TooltipContentProps(42-49)src/cartesian/Area.tsx (1)
Area(1074-1074)
test/cartesian/Area.spec.tsx (2)
src/state/tooltipSlice.ts (1)
TooltipPayloadConfiguration(52-69)test/helper/expectLastCalledWith.ts (1)
expectLastCalledWith(14-34)
⏰ Context from checks skipped due to timeout of 90000ms. You can increase the timeout in your CodeRabbit configuration to a maximum of 15 minutes (900000ms). (2)
- GitHub Check: Build, Test, Pack
- GitHub Check: Analyze (javascript-typescript)
🔇 Additional comments (67)
test/component/Cursor.spec.tsx (2)
11-11: LGTM: Import adds type safety to tests.The import of
TooltipPayloadfrom the internal tooltipSlice module is appropriate for this test file and enables explicit typing of the payload variable in the tests below.
167-167: LGTM: Type annotation and graphicalItemId addition align with PR objectives.The explicit
TooltipPayloadtype annotation adds type safety, and thegraphicalItemIdproperty correctly implements the PR's goal of wiring graphical item IDs into tooltip payloads.src/polar/RadialBar.tsx (1)
365-399: Tooltip payload wiring forgraphicalItemIdlooks correct and consistently typed.
WithIdRequired<PropsWithDefaults>+settings.graphicalItemId: id+ passingid={props.id}ensures the registered id is available downstream (selectors/payload generation).Also applies to: 464-499
test/component/DefaultTooltipContent.spec.tsx (1)
3-7: Test updates correctly reflect the extended payload shape (graphicalItemId) and use the exported prop type.Also applies to: 38-53
src/polar/Radar.tsx (1)
158-197:Radartooltip entry settings now correctly includegraphicalItemIdsourced from the registered id.Also applies to: 571-599
test/cartesian/Scatter.spec.tsx (1)
579-623: Tooltip payload assertions appropriately validate the presence ofgraphicalItemIdwithout overfitting to an exact generated value.test/cartesian/Line.spec.tsx (1)
457-481: Line tooltip payload test correctly assertsgraphicalItemIdpresence using a stable pattern.omnidoc/readProject.spec.ts (1)
79-86: Snapshot update for Funnel reflected public properties looks consistent with a narrowed runtime surface.test/chart/Treemap.spec.tsx (1)
373-476: Treemap event payload tests now correctly assert the presence of the generatedidwhile keeping existing behavioral checks intact.Also applies to: 517-620, 644-742
test/cartesian/Bar.spec.tsx (1)
1587-1722: PayloadgraphicalItemIdassertions are good; please sanity-check whether interaction state should also carry it.
Right now the test expectsitemInteraction.hover.graphicalItemIdto stayundefinedeven though payload entries have ids—if that’s intentional (scope-limited to payload only), all good; otherwise this is an easy place to thread it through.src/util/Constants.ts (1)
28-40: Constant rename/addition looks consistent; consider tightening the doc comment
The newDATA_ITEM_GRAPHICAL_ITEM_ID_ATTRIBUTE_NAMEand its usage intent are clear. Minor: the comment says “Unlike dataKey, or name, it is always unique” — might be worth explicitly saying “graphical item id” is unique per rendered item (and not per data point).test/component/Tooltip/Tooltip.formatter.spec.tsx (1)
34-36: Good test stabilization: explicit Bar ids +graphicalItemIdassertions
Addingid="bar-with-function"/id="bar-pv"makes the newgraphicalItemIdexpectations deterministic and aligns with the PR objective.Also applies to: 57-58, 77-78, 113-115, 150-151, 170-171
test/chart/LineChart.spec.tsx (1)
827-860: LGTM: tooltip integration test coversgraphicalItemIdend-to-end
Explicitid="line-y"plus the selector assertion should catch regressions in the tooltip payload pipeline.src/polar/Pie.tsx (5)
43-44: Import/update to use graphical item id attribute looks consistent
No concerns with addingDATA_ITEM_GRAPHICAL_ITEM_ID_ATTRIBUTE_NAMEalongside the index attribute for touch picking.
325-360: LGTM: Pie tooltip entry settings now carrygraphicalItemId
ThreadingidintoSetPieTooltipEntrySettingsand writing it intotooltipEntrySettings.settings.graphicalItemIdmatches the intended pipeline.
551-573: Correct DOM wiring: sectors expose both index + graphical item id
Adding[DATA_ITEM_GRAPHICAL_ITEM_ID_ATTRIBUTE_NAME]: idshould make item tooltips resolvable even whendataKey/nameare ambiguous.
646-655: Good: sector tooltip payload includesgraphicalItemId
This ensures consumers can disambiguate tooltip entries for identicaldataKeys across multiple pies.
871-887: Good propagation: PieImpl passes the resolved id into tooltip settings
id={id}onSetPieTooltipEntrySettingskeeps the id consistent between state and payload.test/state/selectors/pieSelectors.spec.tsx (1)
74-88: Solid coverage: selector outputs now assertgraphicalItemIdconsistently
The expectations validategraphicalItemIdacross initial render, after interaction (dataKey change), and with custom data props.Also applies to: 122-136, 170-184, 218-232, 266-280, 314-328, 362-376, 423-437, 471-485, 519-533, 567-581, 615-629, 663-677, 711-725, 796-810, 843-857
src/cartesian/Bar.tsx (3)
87-88: Good: internal Bar id typed asGraphicalItemId
This aligns the Bar pipeline with the store’s id type and avoids accidental mixing with unrelated string ids.Also applies to: 352-357
382-416: LGTM: Bar tooltip settings now includegraphicalItemId
SettingtooltipEntrySettings.settings.graphicalItemId = idis the key wiring needed for the tooltip payload additions.
1042-1076: Good propagation: resolved id is passed into tooltip settings and Bar impl
RegisterGraphicalItemId→SetBarTooltipEntrySettings id={id}keeps tooltip identity stable and testable.test/component/Tooltip/Tooltip.content.spec.tsx (1)
24-32: Good coverage: deterministicid→ assertedgraphicalItemIdin payload.
This test does a nice job pinning the new linkage end-to-end forArea.Also applies to: 77-182
test/chart/ScatterChart.spec.tsx (1)
1436-1456: LGTM: Scatter tooltip payload/config assertions now verifygraphicalItemId.Also applies to: 1511-1520, 2267-2274, 2442-2488
test/state/selectors/selectors.spec.tsx (2)
54-100: LGTM: selector expectations now propagategraphicalItemIdend-to-end.Also applies to: 261-509, 1246-1326
1-3: Tests: confirmvi.useFakeTimers()is applied for this file (global setup or add here).
Guidelines require fake timers due to Redux batching + rAF timing. If not globally enabled, add abeforeEach(() => vi.useFakeTimers()).Also applies to: 694-699
src/cartesian/Scatter.tsx (2)
264-307: LGTM: Scatter tooltip settings now includegraphicalItemIdderived fromid.Also applies to: 758-768
439-448: Nice: DOM attribute is now based ongraphicalItemIdinstead ofdataKey.
This aligns touch/hover targeting with the new identity model.src/chart/SunburstChart.tsx (2)
49-94: LGTM:id?: stringadded to Sunburst public props for deterministic identity.
129-163: Good:RegisterGraphicalItemIdnow drivessettings.graphicalItemIdfor Sunburst tooltips.Also applies to: 202-225, 365-380
test/component/Tooltip/Tooltip.payload.spec.tsx (2)
165-173: LGTM: tests now assertgraphicalItemIdfor data-on-item LineChart payloads/configs.Also applies to: 467-957, 969-1136, 1138-1212
442-446: Tests: confirm fake timers are enabled (global setup or add here).
If not already handled bycreateSelectorTestCase/ test setup, addvi.useFakeTimers()per guidelines.src/cartesian/Line.tsx (2)
221-256: Good: tooltip entry settings now carrygraphicalItemId.
AddinggraphicalItemId: idinTooltipPayloadConfiguration.settingsis the right place to attach this identifier for downstream selectors/searchers.
835-869: Good: usesRegisterGraphicalItemIdoutput to populate tooltip settings.
This ensures the tooltip gets the same id that’s used for state/graphical-item registration (and not the optional external prop directly).src/state/selectors/funnelSelectors.ts (2)
10-23: Good:ResolvedFunnelSettings.idmakes the identity explicit and typed.
This aligns funnel trapezoid computation with the new graphical-item-id plumbing.
30-83: Good: selector forwardsgraphicalItemId; verify that graphical item IDs are guaranteed unique per chart instance.The implementation relies on IDs being unique for tooltip/event disambiguation—specifically,
touchEventsMiddlewareuses.find(item => item.id === graphicalItemId)which returns only the first match. If duplicate IDs exist, the wrong item could be selected. While the codebase documents thatgraphicalItemIdshould be unique (seesrc/state/graphicalItemsSlice.tslines 15–26), the reducer does not validate uniqueness when items are added or updated. Confirm that user-provided or auto-generated IDs are guaranteed to be unique per chart instance, or add validation to prevent regressions.test/component/Tooltip/defaultIndex.spec.tsx (3)
14-76: Good: BarChart expectations now assertgraphicalItemIdin tooltip payload (including hover update).
Nice use ofshowTooltip+expectLastCalledWithfor stable assertions.
85-120: Good: LineChart (multi XAxes) payload now carriesgraphicalItemIdand remains deterministic.
133-209: Good: PieChart payload assertions updated forgraphicalItemId, including hover change.src/cartesian/Area.tsx (1)
289-324: Good:graphicalItemIdis added to Area tooltip entry settings, andidis enforced for the internal call.src/state/selectors/touchSelectors.ts (1)
4-44: The selector implementation is correct and the concern in this review comment is unfounded.Analysis: The code at line 31 properly matches tooltip configurations by
settings.graphicalItemId. ThegraphicalItemIdfield is present inTooltipEntrySettingsbecause it's part of thePayloadinterface (defined inDefaultTooltipContent.tsx). More importantly, theidprop is always guaranteed to be a non-null string because all graphical item components (Line, Bar, Pie, etc.) pass theiridthrough theuseUniqueIdhook before callingSetTooltipEntrySettings. The hook generates a unique ID if none is provided, ensuring the value is never undefined.Therefore: All tooltip configurations will reliably have
graphicalItemIdset, the selector matching will work as intended, and there is no risk of silent failures returning undefined. No backwards-compatibility fallback is needed.test/polar/Pie.spec.tsx (5)
1-56: Import and setup changes look correct.The updated imports properly bring in
Mocktype and the renamedDATA_ITEM_GRAPHICAL_ITEM_ID_ATTRIBUTE_NAMEconstant. The test file correctly imports from internal source paths which is acceptable for test files.
334-416: Test assertions properly validate the new graphicalItemId in activeShape payload.The
Mock<(props: PieSectorDataItem) => ReactNode>typing and@ts-expect-errorcomments indicate known typing gaps that should be addressed separately. TheexpectLastCalledWithhelper is correctly used per coding guidelines, and thegraphicalItemId: 'pie-y'assertion properly matches theid="pie-y"prop on the Pie component.
786-843: Tooltip integration tests correctly updated with graphicalItemId.The test case properly:
- Adds
id="cy-pie"to the Pie component- Updates
mockTouchingElementcalls to use the new signature with graphicalItemId- Verifies
graphicalItemId: 'cy-pie'in tooltip state assertions
1863-1938: Event handler tests correctly verify graphicalItemId in tooltip payload.The onClick test properly:
- Adds
id="pie-uv"to the Pie component- Verifies
graphicalItemId: 'pie-uv'in thetooltipPayloadarray- Uses
expectLastCalledWithhelper as per coding guidelines
1086-1092: Verify ifsetActiveMouseOverItemIndexfrom the touch middleware correctly populatesgraphicalItemIdin the hover state.The implementation in
touchEventsMiddleware.ts(lines 56-67) does extractgraphicalItemIdfrom the element'sDATA_ITEM_GRAPHICAL_ITEM_ID_ATTRIBUTE_NAMEattribute viaelementFromPoint. It then dispatchessetActiveMouseOverItemIndexwith this value.However, the test expects
graphicalItemId: undefinedin the hover state. This inconsistency suggests one of the following:
- The
setActiveMouseOverItemIndexaction is not correctly passingactiveGraphicalItemIdto the reducer, despite extracting it in the middleware- A different code path handles touch events that doesn't use
setActiveMouseOverItemIndex- The test's mock setup with
mockTouchingElement('2', 'cy-pie')is not properly simulating the actual touch event flowThe mouse hover equivalent works correctly because it sets
graphicalItemId: 'cy-pie'(line 842), suggesting the inconsistency is real and needs investigation into which step of the touch event pipeline is dropping thegraphicalItemId.src/chart/Sankey.tsx (4)
31-32: Imports correctly added for ID registration pattern.The
WithIdRequiredandRegisterGraphicalItemIdimports align with the pattern used across other chart components in this PR.
533-563: SetSankeyTooltipEntrySettings correctly wires graphicalItemId into tooltip configuration.The component properly:
- Accepts
idin its props via the updated Pick type- Includes
graphicalItemId: idin the tooltip settingsThis matches the pattern used in other components like
SetFunnelTooltipEntrySettings.
951-955: Internal type definitions correctly establish ID-required contract.The
InternalSankeyPropstype properly usesWithIdRequired<PropsWithResolvedDefaults>to ensure the internal implementation always receives a resolved ID, while the publicPropstype allows an optional ID.
1096-1154: Sankey component correctly implements the RegisterGraphicalItemId pattern.The implementation:
- Extracts
externalIdfrom resolved props- Wraps the content with
RegisterGraphicalItemIdusing type"sankey"- Passes the resolved
idto bothSetSankeyTooltipEntrySettingsandSankeyImplThis follows the established pattern from other components in this PR.
src/cartesian/Funnel.tsx (7)
48-50: Imports correctly added for graphical item ID wiring.The imports for
GraphicalItemId,RegisterGraphicalItemId, andWithIdRequiredalign with the pattern established across other chart components.
67-70: InternalFunnelProps correctly defines id as required.Using
GraphicalItemIdtype foridensures type consistency across the codebase.
134-172: SetFunnelTooltipEntrySettings correctly integrates graphicalItemId.The component properly:
- Accepts
idvia the updated Pick type (line 149)- Includes
graphicalItemId: idin tooltip settings (line 167)This matches the pattern in other components.
224-232: Destructuringidfrom trapezoidProps prevents passing it to DOM elements.This is a good practice to avoid React warnings about unknown DOM attributes. The
idis destructured but not used here since it's not needed in the individual trapezoid rendering context.
476-537: computeFunnelTrapezoids correctly adds graphicalItemId to tooltip payload.The function properly:
- Accepts
graphicalItemIdparameter (line 485)- Includes it in the
TooltipPayloadarray (line 536)This ensures the tooltip payload carries the graphical item identifier for each funnel segment.
592-601: Funnel component correctly implements RegisterGraphicalItemId pattern.The implementation:
- Extracts
externalIdfrom resolved props and spreads remaining props- Wraps content with
RegisterGraphicalItemIdusing type"funnel"- Passes the resolved
idtoFunnelImplThis is consistent with the pattern used in Sankey and other chart components.
381-427: FunnelImpl correctly uses the id in funnelSettings for selector consumption.The
idis properly:
- Included in the
funnelSettingsobject (line 413)- Added to the dependency array of
useMemo(line 425)This ensures the selector receives the graphical item ID for proper tooltip coordination.
test/component/Tooltip/Tooltip.visibility.spec.tsx (4)
4-35: Import change looks fine; ensureDefaultZIndexesis part of the intended test surface.
109-307: Good: explicitidprops makegraphicalItemIdassertions deterministic.
441-448: Touch-mocking updated correctly forgraphicalItemId.
767-801: Assertions updated consistently to includeid/graphicalItemId.Also applies to: 1060-1232
src/chart/Treemap.tsx (2)
42-43: LGTM: Treemap now supports an externalidprop, consistent with other items.Also applies to: 401-403
547-577: LGTM:graphicalItemIdis now included in Treemap tooltip entry settings.Also applies to: 919-926
test/component/Tooltip/itemSorter.spec.tsx (2)
51-62: Nice: explicit ids on composed items make itemSorter tests stable and exercisegraphicalItemId.
78-436: Assertions updated thoroughly to includegraphicalItemIdacross chart types.Also applies to: 635-740, 914-959, 967-1276, 1278-1920, 1929-2314, 2321-2706
test/cartesian/Area.spec.tsx (2)
4-4: Import updates look consistent with the new tooltip payload shape.Also applies to: 24-24
820-887: Good upgrade: strongly typedtooltipSpy+graphicalItemIdassertion improves coverage.
| import React, { ReactNode } from 'react'; | ||
| import { beforeEach, describe, expect, it, Mock } from 'vitest'; |
There was a problem hiding this comment.
🧩 Analysis chain
🏁 Script executed:
# Read the spec file to see vi usage
cat -n test/component/Tooltip/Tooltip.content.spec.tsx | head -50Repository: recharts/recharts
Length of output: 2146
🏁 Script executed:
# Check for Vitest configuration
fd -e 'config.ts' -e 'config.js' | grep -E '(vitest|vite)' | head -20Repository: recharts/recharts
Length of output: 79
🏁 Script executed:
# Look for vitest config in the repo root or common locations
find . -maxdepth 2 -type f \( -name 'vitest.config.*' -o -name 'vite.config.*' \) 2>/dev/nullRepository: recharts/recharts
Length of output: 101
🏁 Script executed:
cat -n ./vitest.config.mtsRepository: recharts/recharts
Length of output: 3280
Import vi from vitest for clarity and IDE support.
Line 17 uses vi.fn() but vi is not imported. While Vitest's globals: true configuration makes this work at runtime, explicit imports improve code clarity and enable better IDE autocompletion.
-import { beforeEach, describe, expect, it, Mock } from 'vitest';
+import { beforeEach, describe, expect, it, Mock, vi } from 'vitest';Also applies to: 16-18
🤖 Prompt for AI Agents
In test/component/Tooltip/Tooltip.content.spec.tsx lines 1-2, the test uses
vi.fn() later but vi is not explicitly imported; update the imports to include
vi from 'vitest' (e.g., import { beforeEach, describe, expect, it, vi, Mock }
from 'vitest' or add a separate import for vi) so the symbol is explicit for
IDEs and type support.
Codecov Report✅ All modified and coverable lines are covered by tests. Additional details and impacted files@@ Coverage Diff @@
## main #6765 +/- ##
=======================================
Coverage 93.70% 93.70%
=======================================
Files 515 515
Lines 43011 43082 +71
Branches 5018 5021 +3
=======================================
+ Hits 40302 40370 +68
- Misses 2703 2706 +3
Partials 6 6 ☔ View full report in Codecov by Sentry. 🚀 New features to boost your workflow:
|
|
Staging Deployment Details
These deployments will remain available for 30 days. To update snapshots: Comment |
Bundle ReportChanges will increase total bundle size by 2.04kB (0.08%) ⬆️. This is within the configured threshold ✅ Detailed changes
Affected Assets, Files, and Routes:view changes for bundle: recharts/bundle-es6Assets Changed:
view changes for bundle: recharts/bundle-umdAssets Changed:
view changes for bundle: recharts/bundle-cjsAssets Changed:
|
| maxRadius: 275.77164466275354, | ||
| midAngle: 38.579169175195666, | ||
| middleRadius: 100, | ||
| // @ts-expect-error somehow name is a number even though type says string |
|
thanks! |
Description
No bugfixes yet, just wiring the graphicalItemId in tooltip payload where it will be useful for fixing bugs later.
Related Issue
#6075
Motivation and Context
In several PRs recently this came up as a change that would be useful but nobody wanted to do that because it's too big! So I did.
Types of changes
Checklist:
Summary by CodeRabbit
Release Notes
idprop for explicit identification and improved tooltip linking.✏️ Tip: You can customize this high-level summary in your review settings.