-
Notifications
You must be signed in to change notification settings - Fork 17
diagram: fix type errors from React 19 and recharts v3 upgrade #163
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Conversation
|
@codex review |
Code ReviewThis PR handles compatibility updates for React 19 and recharts v3. Overall, the approach is solid and well-documented. Here's my feedback: Positives
Issues & Concerns1. Missing Callback Memoization (Bug Risk)handleLayoutChange = (layoutInfo: ChartLayoutInfo | undefined) => {
this.layoutInfo = layoutInfo;
};The }, [offset, chartHeight, onLayoutChange]);Since 2. Removal of
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
💡 Codex Review
Here are some automated review suggestions for this pull request.
Reviewed commit: 52974a86f9
ℹ️ About Codex in GitHub
Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you
- Open a pull request for review
- Mark a draft as ready
- Comment "@codex review".
If Codex has suggestions, it will comment; otherwise it will react with 👍.
Codex can also answer questions or update the PR. Try commenting "@codex address that feedback".
src/diagram/LookupEditor.tsx
Outdated
| handleMouseDown: CategoricalChartFunc = (nextState, event) => { | ||
| this.setState({ inDrag: true }); | ||
| this.updatePoint(details); | ||
| this.updatePoint(nextState.activeTooltipIndex, event); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Guard against null nextState from Recharts events
Recharts’ onMouseDown passes the return value of getMouseInfo, which can be null when the pointer is outside the plot area (e.g., clicking on axis labels or margins). This handler now unconditionally dereferences nextState.activeTooltipIndex, so a null nextState will throw at runtime and break lookup editing. Adding a null check (or defaulting nextState to an empty object) before reading activeTooltipIndex would prevent crashes in those out‑of‑range clicks.
Useful? React with 👍 / 👎.
Codecov Report✅ All modified and coverable lines are covered by tests. Additional details and impacted files@@ Coverage Diff @@
## main #163 +/- ##
=======================================
Coverage 73.56% 73.56%
=======================================
Files 44 44
Lines 14876 14876
=======================================
Hits 10943 10943
Misses 3933 3933 ☔ View full report in Codecov by Sentry. 🚀 New features to boost your workflow:
|
52974a8 to
2c3b392
Compare
|
@codex review |
Pull Request ReviewI've completed my review of PR #163 "diagram: fix type errors from React 19 and recharts v3 upgrade". Overall, this is a well-crafted PR that thoughtfully addresses breaking changes from dependency upgrades. Here's my detailed feedback: ✅ Strengths1. Excellent Problem SolvingThe approach to handling the recharts v3 API changes is exemplary:
2. Code Quality
3. Type Safety
🔍 Areas for Improvement1. Missing Test Plan Item
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
💡 Codex Review
Here are some automated review suggestions for this pull request.
Reviewed commit: 2c3b3920d5
ℹ️ About Codex in GitHub
Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you
- Open a pull request for review
- Mark a draft as ready
- Comment "@codex review".
If Codex has suggestions, it will comment; otherwise it will react with 👍.
Codex can also answer questions or update the PR. Try commenting "@codex address that feedback".
src/diagram/LookupEditor.tsx
Outdated
| // Get mouse Y position relative to container | ||
| const nativeEvent = event.nativeEvent; | ||
| let clientY: number | undefined; | ||
| if ('clientY' in nativeEvent && typeof nativeEvent.clientY === 'number') { | ||
| clientY = nativeEvent.clientY; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Handle touch events without nativeEvent access
Recharts forwards touch input to onMouseDown/onMouseMove using the Touch object (via changedTouches[0]), which does not have a nativeEvent property. In that case event.nativeEvent is undefined, so the 'clientY' in nativeEvent check throws and the lookup editor drag will fail on touch devices. Consider detecting touch objects directly (e.g., check event.clientY or event.touches?.[0].clientY) before accessing nativeEvent so touch interactions keep working.
Useful? React with 👍 / 👎.
The React 18 to 19 upgrade changed createRef() to return RefObject<T | null> by default, requiring the Canvas.tsx ref type to be updated. The recharts v2 to v3 upgrade removed the getYScaleByAxisId() method from the LineChart ref (which now forwards to SVGSVGElement). The LookupEditor used this to convert pixel coordinates to data values when dragging points. The fix uses recharts v3's public hooks API (useOffset, useChartHeight) via a ChartLayoutExtractor wrapper component rendered inside the LineChart. This extracts the actual chart layout dimensions at runtime and passes them to the class component via callback, enabling robust pixel-to-data coordinate conversion that adapts to responsive container resizing and future recharts updates.
2c3b392 to
2f3a22a
Compare
Code Review: React 19 and recharts v3 Compatibility FixesOverviewThis PR addresses type compatibility issues arising from the React 18→19 and recharts v2→v3 upgrades. The changes are well-motivated and the solution for the lookup editor is architecturally sound. Positive AspectsCanvas.tsx Change✅ Simple and correct: The ref type change from LookupEditor.tsx Refactoring✅ Public API usage: Migrating from the internal ✅ Clean architecture: The ✅ Well-documented: Excellent inline comments explaining the rationale for design decisions (e.g., why ✅ Improved coordinate conversion: The custom Issues & Concerns1. Missing Test Coverage
|
Summary
Details
The React 18 to 19 upgrade changed
createRef()to returnRefObject<T | null>by default.The recharts v2 to v3 upgrade removed the
getYScaleByAxisId()method from the LineChart ref (which now forwards to SVGSVGElement). The LookupEditor used this to convert pixel coordinates to data values when users drag points on the lookup table chart.The fix introduces a
ChartLayoutExtractorwrapper component that uses recharts v3's public hooks (useOffset,useChartHeight) to extract the actual chart layout dimensions at runtime. This enables robust pixel-to-data coordinate conversion that adapts to responsive container resizing and future recharts updates.Test plan
yarn buildpasses