Skip to content
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

Warning: scheduling a cascading update #1160

Open
rleir opened this issue Jun 8, 2020 · 3 comments
Open

Warning: scheduling a cascading update #1160

rleir opened this issue Jun 8, 2020 · 3 comments
Labels
bug Something isn't working

Comments

@rleir
Copy link
Contributor

rleir commented Jun 8, 2020

Current Behavior
A clear and concise description of what is happening / what the bug is.
@jameshadfield James: This issue is a question not a bug report. Thanks -- Rick
In tree.js ( auspice/src/components/tree/tree.js )
componentDidMount() calls new PhyloTree(this.props.tree.nodes, "LEFT");
Why is this not called in the constructor? This is being done after the component has been put in the DOM. You must have a reason for this.

componentDidMount() {
    if (this.props.tree.loaded) {
      const newState = {};
      newState.tree = new PhyloTree(this.props.tree.nodes, "LEFT");
      renderTree(this, true, newState.tree, this.props);
      if (this.props.showTreeToo) {
        this.setUpAndRenderTreeToo(this.props, newState); /* modifies newState in place */
      }
      this.setState(newState); /* this will trigger an unneccessary CDU :( */
    }
  }

The Chrome performance tool gives us this:
image
At the top-right, see the 'do not enter' sign. At the bottom, see "Tree.componentDidMount Warning: scheduling a cascading update". Cascading means that an update just completed, and we immediately call setState to schedule a new update.
After the "do not enter" sign, off to the right, the script continues to execute long after the tree is displayed.

Expected behavior
A clear and concise description of what you expected to happen instead.
Please tell me what discussions you have had about the tree component, maybe this has something to do with the 'Right' tree?

How to reproduce
Steps to reproduce the current behavior:

  1. Open / run ...
  2. See error

Possible solution
(optional)

Your environment: if browsing Nextstrain online

Your environment: if running Nextstrain locally

  • Operating system:
  • Browser:
  • Version (e.g. auspice 2.7.0):
    2.15.0

Additional context
Add any other context about the problem here.

@rleir rleir added the bug Something isn't working label Jun 8, 2020
@jameshadfield
Copy link
Member

The reason it's in componentDidMount not the constructor is that the DOM element which renderTree will render the tree into is created (by react) after the constructor code is run.

The Phylotree object might be able to be created in the constructor, but the tree cannot be rendered there. Placing all the code in componentDidMount seemed the simplest way to reason with this.

@jameshadfield
Copy link
Member

Thanks for looking into this! Lots of performance improvements to be had here :)

@rleir
Copy link
Contributor Author

rleir commented Jun 8, 2020

James, thanks for the info. Let's link this to #955

All: The 'bug' label gets added automatically. Just saying this in case someone did not know.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working
Projects
None yet
Development

No branches or pull requests

2 participants