Skip to content

Fix conditions for plot being refreshed #118

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Closed
wants to merge 1 commit into from
Closed
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
48 changes: 26 additions & 22 deletions src/factory.js
Original file line number Diff line number Diff line change
Expand Up @@ -84,30 +84,34 @@ export default function plotComponentFactory(Plotly) {
}

componentWillUpdate(nextProps) {
if (
nextProps.revision !== void 0 &&
nextProps.revision === this.props.revision
) {
// if revision is set and unchanged, do nothing
return;
var doNothing = false;

// If revision is set and unchanged, do nothing.
if ((nextProps.revision !== void 0)
&& (nextProps.revision === this.props.revision)) {
doNothing = true;
}

const numPrevFrames = (this.props.frames && this.props.frames.length)
? this.props.frames.length
: 0;
const numNextFrames = (nextProps.frames && nextProps.frames.length)
? nextProps.frames.length
: 0;

/* If none of data, layout, or config have changed identity and the
number of elements in frames has not changed, do nothing. This
prevents infinite loops when the component is re-rendered after
onUpdate. frames *always* changes identity, so check its length
insead. */
if ((nextProps.layout === this.props.layout)
&& (nextProps.data === this.props.data)
&& (nextProps.config === this.props.config)
&& (numNextFrames === numPrevFrames)) {
doNothing = true;
}

const numPrevFrames =
this.props.frames && this.props.frames.length
? this.props.frames.length
: 0;
const numNextFrames =
nextProps.frames && nextProps.frames.length
? nextProps.frames.length
: 0;
if (
nextProps.layout === this.props.layout &&
nextProps.data === this.props.data &&
nextProps.config === this.props.config &&
numNextFrames === numPrevFrames
) {
// prevent infinite loops when component is re-rendered after onUpdate
// frames *always* changes identity so fall back to check length only :(
if (doNothing) {
return;
}

Expand Down