Skip to content

Bug: Resize on hidden graph divs causes Error #3866

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
ghost opened this issue May 15, 2019 · 5 comments · Fixed by #3972
Closed

Bug: Resize on hidden graph divs causes Error #3866

ghost opened this issue May 15, 2019 · 5 comments · Fixed by #3972
Assignees
Labels
bug something broken
Milestone

Comments

@ghost
Copy link

ghost commented May 15, 2019

Discussion: https://community.plot.ly/t/dynamically-change-responsive-layout/23002
Repo sample: https://codesandbox.io/s/9qy1p1k8jy

Error:

Error: Resize must be passed a displayed plot div element.
    at eval (plotly-basic.js:59636)
    at new Promise (<anonymous>)
    at Object.plots.resize (plotly-basic.js:59629)
    at gd._responsiveChartHandler (plotly-basic.js:41558)
@etpinard
Copy link
Contributor

Thanks for posting!

Here's the problematic block:

if(!gd || isHidden(gd)) {
reject(new Error('Resize must be passed a displayed plot div element.'));
}

Rejecting the promise when calling Plotly.Plots.resize(gd) seems fine, but perhaps we could catch it in

gd._responsiveChartHandler = function() { Plots.resize(gd); };

so that graphs with {responsize: true} don't results in a bunch of somewhat unhelpful error logs.

@antoinerg I'd be interesting in hearing your thoughts on this.

@antoinerg
Copy link
Contributor

antoinerg commented May 15, 2019

I think that if the element is not visible, we could silently ignore the error.

Note that you will also get this error if plots are not removed with Plotly.purge. We could definitely catch the error in the responsive handler and then remove the event listener if the div element is not in the DOM anymore. Essentially, plotly.js would do a clean up if needed.

cc @etpinard

@antoinerg
Copy link
Contributor

Updated comment #3866 (comment) above ⬆️

@etpinard
Copy link
Contributor

etpinard commented Jun 7, 2019

Let's try to squeeze this one in v1.49.0

@etpinard etpinard added this to the v1.49.0 milestone Jun 7, 2019
@etpinard etpinard added the bug something broken label Jun 7, 2019
@antoinerg antoinerg self-assigned this Jun 18, 2019
@antoinerg
Copy link
Contributor

@etpinard I guess we have two options here:

1- Ignore all rejected promises

gd._responsiveChartHandler = function() { Plots.resize(gd).catch(Lib.noop); };

2- Do not call resize if div is hidden

gd._responsiveChartHandler = function() { if(!isHidden(gd)) Plots.resize(gd); }; 

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug something broken
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants