Refactor Shape props to reduce bundle sizes#7349
Conversation
|
No actionable comments were generated in the recent review. 🎉 ℹ️ Recent review info⚙️ Run configurationConfiguration used: Organization UI Review profile: CHILL Plan: Pro Run ID: 📒 Files selected for processing (23)
💤 Files with no reviewable changes (8)
WalkthroughThis PR refactors Recharts' shape rendering system from ChangesShape Rendering Architecture
🎯 4 (Complex) | ⏱️ ~60 minutes Possibly Related PRs
Suggested Labels
Suggested Reviewers
🚥 Pre-merge checks | ✅ 4 | ❌ 1❌ Failed checks (1 warning)
✅ Passed checks (4 passed)
✏️ Tip: You can configure your own custom pre-merge checks in the settings. ✨ Finishing Touches📝 Generate docstrings
🧪 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 |
|
Tip All tests passed and all changes approved!🟢 UI Tests: 193 tests unchanged |
|
Staging Deployment Details
These deployments will remain available for 30 days. To update snapshots: Comment |
Move Shape off the shared shapeType switch so each consumer provides its own default renderer. This keeps the runtime behavior intact while letting bundles tree-shake unrelated shapes. Measured with scripts/treeshaking.ts (tree-shaken / min+gzip): - Bar: 308.72 KB -> 288.03 KB / 30.12 KB -> 27.61 KB - BarStack: 312.40 KB -> 291.72 KB / 30.47 KB -> 27.96 KB - Funnel: 266.92 KB -> 243.50 KB / 26.49 KB -> 23.85 KB - Line: 292.08 KB -> 271.77 KB / 28.44 KB -> 25.67 KB - Pie: 282.73 KB -> 268.92 KB / 28.00 KB -> 26.06 KB - RadialBar: 292.61 KB -> 271.21 KB / 28.86 KB -> 26.27 KB - Scatter: 287.81 KB -> 269.78 KB / 28.14 KB -> 25.76 KB Co-authored-by: Copilot <[email protected]>
Bundle ReportChanges will decrease total bundle size by 33.87kB (-0.61%) ⬇️. 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:
view changes for bundle: recharts/bundle-treeshaking-cartesianAssets Changed:
view changes for bundle: recharts/bundle-treeshaking-polarAssets Changed:
|
Codecov Report✅ All modified and coverable lines are covered by tests. Additional details and impacted files@@ Coverage Diff @@
## main #7349 +/- ##
=======================================
Coverage 89.03% 89.04%
=======================================
Files 548 548
Lines 40522 40534 +12
Branches 5570 5567 -3
=======================================
+ Hits 36079 36093 +14
+ Misses 4434 4432 -2
Partials 9 9 ☔ 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 |
Description
The
Shapecomponent had an unfortunate design where it accepted a string enum and resolved that into individual components. This works but it forces theShapeto import all components in compile time so that it is ready to resolve them at runtime, which forces all of them into each consumer bundle. Now, most consumers of Shape don't actually use all of the shapes, they only use one hardcoded one so we inflate the bundle sizes for no reason.So I swapped it from string enum into actually accepting the component as a prop, and added that component as default and that reduces the bundle sizes because now we don't import everything. You can see this effect in the treeshaking bundle snapshot.
Why now? Because I am adding more default shapes in the animation PR so this effect would be even more pronounced, so let's get it done now.
Shapeis not exported so it's a private component and so I consider this a backwards compatible change.Bundle size measurements
Measured with
scripts/treeshaking.tson the previousHEADversus this branch (tree-shaken / min+gzip):Motivation and Context
Smaller bundle size
Types of changes
Checklist:
Summary by CodeRabbit
Refactor
Tests