Skip to content
This repository has been archived by the owner on Jun 3, 2024. It is now read-only.

Don't attempt to resize unmounted graphs #563

Merged
merged 7 commits into from
Jun 12, 2019
Merged

Conversation

wbrgss
Copy link
Contributor

@wbrgss wbrgss commented Jun 7, 2019

Simple check for a graph element before a resize attempt. Fixes #534.

@alexcjohnson
Copy link
Collaborator

We probably should remove the resize listener in componentWillUnmount as well. I'm imagining a case where you unmount and remount a plot many times, and we'll end up with a million resize listeners. Plotly.Plots.resize should be smart enough to not actually redraw the plot more than once, but there's still some overhead (and I wouldn't be surprised if there's a case where it would do many redraws).

Do we need this same conditional around the resize and bindEvents in plot too?

this.bindEvents();
Plotly.Plots.resize(document.getElementById(id));

Much less likely, but in principle the plot element could be removed before it finishes drawing and enters that .then

@wbrgss
Copy link
Contributor Author

wbrgss commented Jun 10, 2019

probably should remove the resize listener in componentWillUnmount as well.

In order to do this I moved the resize handler from its anon function into a named function bound in the constructor.

@alexcjohnson
Copy link
Collaborator

Looks great, thanks! Given that this is a bugfix, would you mind locking it down with a test?

Also changelog

I'm 99% convinced the way you did the removeEventListener is right - was worried that we were referencing a class attr instead of an instance attr but I guess this.graphResize = this.graphResize.bind(this); ensures it's an instance attr and we're doing the right thing.

wbrgss added a commit that referenced this pull request Jun 12, 2019
@wbrgss
Copy link
Contributor Author

wbrgss commented Jun 12, 2019

I added an integration test.

Before the changes in this PR (failing test):

======================================================================
ERROR: test_unmounted_graph_resize (test.test_integration.Tests)
----------------------------------------------------------------------
Traceback (most recent call last):
  File "/home/plotly/Workspace/dash-core-components/test/test_integration.py", line 138, in test_unmounted_graph_resize
    raise Exception('browser error logged during test', entry)
Exception: ('browser error logged during test', {'level': 'SEVERE', 'message': 'http://localhost:8050/_dash-component-suites/dash_core_components/plotly-1.47.0.min.js?v=0.48.0&m=1555705071 6:2043297 Uncaught Error: DOM element provided is null or undefined', 'source': 'javascript', 'timestamp': 1560296987995})

----------------------------------------------------------------------
Ran 1 test in 5.934s

After:

.
----------------------------------------------------------------------
Ran 1 test in 5.954s

OK

(no exceptions raised)

Copy link
Collaborator

@alexcjohnson alexcjohnson left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Love it. Thank you! 💃

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

dcc.Graph attempts to resize umounted Graphs
2 participants