ktmud commented on a change in pull request #9400: Build: fix hot reload for
charts
URL:
https://github.com/apache/incubator-superset/pull/9400#discussion_r399610146
##########
File path: superset-frontend/src/chart/ChartRenderer.jsx
##########
@@ -78,28 +114,37 @@ class ChartRenderer extends React.Component {
}
shouldComponentUpdate(nextProps) {
- const resultsReady =
- nextProps.queryResponse &&
- ['success', 'rendered'].indexOf(nextProps.chartStatus) > -1 &&
- !nextProps.queryResponse.error &&
- !nextProps.refreshOverlayVisible;
-
- if (resultsReady) {
- this.hasQueryResponseChange =
- nextProps.queryResponse !== this.props.queryResponse;
-
- if (
- this.hasQueryResponseChange ||
- nextProps.annotationData !== this.props.annotationData ||
- nextProps.height !== this.props.height ||
- nextProps.width !== this.props.width ||
- nextProps.triggerRender ||
- nextProps.formData.color_scheme !== this.props.formData.color_scheme
- ) {
- return true;
- }
+ // if no results loaded, don't render
+ if (
+ !nextProps.queryResponse ||
+ nextProps.queryResponse.error ||
+ nextProps.refreshOverlayVisible
+ ) {
+ return false;
+ }
+
+ this.hasQueryResponseChange =
+ this.props.queryResponse !== nextProps.queryResponse;
+
+ // current chart status
+ const chartStatus = this.props.chartStatus;
+ // `rendered` status is set right after `success` or `loading`,
+ // don't trigger rerender here (see `actions.chartRenderingSucceeded`).
+ // note that even though render is not triggered, the props will still be
+ // updated.
+ if (
+ (chartStatus === 'success' || chartStatus === 'loading') &&
+ nextProps.chartStatus === 'rendered'
+ ) {
+ return false;
+ }
+
+ // already successfully rendered, only rerender when some prop is updated
+ if (chartStatus === 'rendered' || chartStatus === 'success') {
+ return !deepEqual(this.props, nextProps, 2);
Review comment:
For hot reload to work, `SuperChart` has to re-render every time the
re-render of `ChartRenderer` happens. But a shallow compare may return true
because no real props were actually updated.
I'm not worried about duplicating checks for above props as they were for
handling the most common triggers and there were only two to three of them. A
fixed list of fields was the first thing I tried, but ran into some edge cases
that didn't interact with hot reload well. Current approach looks simpler and
more robust.
----------------------------------------------------------------
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
For queries about this service, please contact Infrastructure at:
[email protected]
With regards,
Apache Git Services
---------------------------------------------------------------------
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]