fix: replace PureComponent with shouldComponentUpdate#534
Conversation
Codecov Report
@@ Coverage Diff @@
## master #534 +/- ##
==========================================
+ Coverage 75.57% 75.63% +0.05%
==========================================
Files 181 181
Lines 5651 5684 +33
Branches 1102 1102
==========================================
+ Hits 4271 4299 +28
- Misses 1364 1369 +5
Partials 16 16
Continue to review full report at Codecov.
|
|
hi @patrykkopycinski thanks for this. I'm in the meantime of a refactoring that will move away from react for some of these components (the one used to render the chart). |
|
Sounds great @markov00! Do you know maybe when you will be able to merge your refactor? Because our app is heavily utilizing charts, so it has a big footprint on the performance |
I will push the PR today, it needs a review and then it will be merged |
markov00
left a comment
There was a problem hiding this comment.
@patrykkopycinski let's merge this. I will merge mine changes later.
Thanks for the contribution
| } | ||
|
|
||
| shouldComponentUpdate(nextProps: AreaGeometriesDataProps, nextState: AreaGeometriesDataState) { | ||
| return !deepEqual(this.props, nextProps) || !deepEqual(this.state, nextState); |
There was a problem hiding this comment.
you can avoid checking the equality of the state. This is not used anymore in this component and should be removed (there is no relevant use of the overPoint state object in the component)
| } | ||
|
|
||
| shouldComponentUpdate(nextProps: BarGeometriesDataProps, nextState: BarGeometriesDataState) { | ||
| return !deepEqual(this.props, nextProps) || !deepEqual(this.state, nextState); |
There was a problem hiding this comment.
same here, overBar is no more used (no one is setting it), you can remove the deepEqual for the state
| } | ||
|
|
||
| shouldComponentUpdate(nextProps: LineGeometriesDataProps, nextState: LineGeometriesDataState) { | ||
| return !deepEqual(this.props, nextProps) || !deepEqual(this.state, nextState); |
Codecov Report
@@ Coverage Diff @@
## master #534 +/- ##
==========================================
+ Coverage 75.57% 75.80% +0.22%
==========================================
Files 181 193 +12
Lines 5651 5844 +193
Branches 1102 1116 +14
==========================================
+ Hits 4271 4430 +159
- Misses 1364 1397 +33
- Partials 16 17 +1
Continue to review full report at Codecov.
|
Codecov Report
@@ Coverage Diff @@
## master #534 +/- ##
=========================================
+ Coverage 75.57% 75.8% +0.22%
=========================================
Files 181 193 +12
Lines 5651 5844 +193
Branches 1102 1116 +14
=========================================
+ Hits 4271 4430 +159
- Misses 1364 1397 +33
- Partials 16 17 +1
Continue to review full report at Codecov.
|
|
Thank you very much for help @markov00 💪 |
## [17.0.1](v17.0.0...v17.0.1) (2020-02-05) ### Bug Fixes * replace PureComponent with shouldComponentUpdate ([#534](#534)) ([5043725](5043725))
|
🎉 This PR is included in version 17.0.1 🎉 The release is available on: Your semantic-release bot 📦🚀 |
This commit replaces React.PureComponent with React.Component with custom shouldComponentUpdate that deeply compares props. Also, it fixes shouldComponentUpdate logic in ChartContainerComponent that caused the component to re-render every time the props have changed.
This commit replaces React.PureComponent with React.Component with custom shouldComponentUpdate that deeply compares props. Also, it fixes shouldComponentUpdate logic in ChartContainerComponent that caused the component to re-render every time the props have changed. Co-authored-by: patrykkopycinski <contact@patrykkopycinski.com>
## [17.0.1](elastic/elastic-charts@v17.0.0...v17.0.1) (2020-02-05) ### Bug Fixes * replace PureComponent with shouldComponentUpdate ([opensearch-project#534](elastic/elastic-charts#534)) ([e06aeb2](elastic/elastic-charts@e06aeb2))
Summary
During working on elastic/kibana#56587 I have found out that charts-related components are probably re-renders unnecessarily, so I have decided to verify that and here is the outcome from https://github.com/welldone-software/why-did-you-render
Each line in the console means unnecessary component's re-render and after the row is expanded we can see which props are equal by value but not by reference, so it causes

PureComponentto re-render.After my changes

Checklist
Use
strikethroughsto remove checklist items you don't feel are applicable to this PR.src/index.ts(and stories only import from../srcexcept for test data & storybook)