Skip to content

Commit d071144

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 d071144

File tree

1 file changed

+16
-4
lines changed

1 file changed

+16
-4
lines changed

src/factory.js

Lines changed: 16 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -103,23 +103,35 @@ 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+
/*
119+
* If none of data, layout, or config have changed identity and the
120+
* number of elements in frames has not changed, do nothing. This
121+
* prevents infinite loops when the component is re-rendered after
122+
* onUpdate. frames *always* changes identity, so check its length
123+
* insead.
124+
*/
115125
if (
116126
nextProps.layout === this.props.layout &&
117127
nextProps.data === this.props.data &&
118128
nextProps.config === this.props.config &&
119129
numNextFrames === numPrevFrames
120130
) {
121-
// prevent infinite loops when component is re-rendered after onUpdate
122-
// frames *always* changes identity so fall back to check length only :(
131+
doNothing = true;
132+
}
133+
134+
if (doNothing) {
123135
return;
124136
}
125137

0 commit comments

Comments
 (0)