Skip to content

Commit b84e435

Browse files
jaredrcleghorndmt0
authored andcommitted
Fix conditions for plot being refreshed
Previously, chaning the revision prop alone was not sufficient to cause the plot to be refreshed, contrary to the behavior indicated in the REAMDE. Fix this so that the revision prop can be used to force the plot to be refreshed. Resolves: #59
1 parent 7ed0f03 commit b84e435

File tree

1 file changed

+15
-4
lines changed

1 file changed

+15
-4
lines changed

Diff for: src/factory.js

+15-4
Original file line numberDiff line numberDiff line change
@@ -103,23 +103,34 @@ export default function plotComponentFactory(Plotly) {
103103
componentWillUpdate(nextProps) {
104104
this.unmounting = false;
105105

106+
let doNothing = false;
107+
108+
// If revision is set and unchanged, do nothing.
106109
if (nextProps.revision !== void 0 && nextProps.revision === this.props.revision) {
107-
// if revision is set and unchanged, do nothing
108-
return;
110+
doNothing = true;
109111
}
110112

111113
const numPrevFrames =
112114
this.props.frames && this.props.frames.length ? this.props.frames.length : 0;
113115
const numNextFrames =
114116
nextProps.frames && nextProps.frames.length ? nextProps.frames.length : 0;
117+
118+
/* If none of data, layout, or config have changed identity and the
119+
* number of elements in frames has not changed, do nothing. This
120+
* prevents infinite loops when the component is re-rendered after
121+
* onUpdate. frames *always* changes identity, so check its length
122+
* insead.
123+
*/
115124
if (
116125
nextProps.layout === this.props.layout &&
117126
nextProps.data === this.props.data &&
118127
nextProps.config === this.props.config &&
119128
numNextFrames === numPrevFrames
120129
) {
121-
// prevent infinite loops when component is re-rendered after onUpdate
122-
// frames *always* changes identity so fall back to check length only :(
130+
doNothing = true;
131+
}
132+
133+
if (doNothing) {
123134
return;
124135
}
125136

0 commit comments

Comments
 (0)