-
-
Notifications
You must be signed in to change notification settings - Fork 1.9k
Plots.resize - additional check for gd.layout #2710
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
Plots.resize - additional check for gd.layout #2710
Conversation
Interesting, thanks for bringing this up @rafalbromirski! Seems like a reasonable check but the source must be a little different from what you've identified. The reason However if you call Can you add a test to the resize promise test suite mimicking this situation? I'm thinking: var resizePromise = Plotly.Plots.resize(initialDiv);
// now purge and detach the element before the resize timer runs out
Plotly.purge(initialDiv);
initialDiv.parentElement.removeChild(initialDiv);
// then wait for the promise as usual, if it doesn't error the test passes
resizePromise.catch(failTest).then(done); hmm, looks like that test file doesn't have our robust promise error handling ( |
@alexcjohnson thanks for explaining! Will look into tests in my spare time. |
e1d47e3
to
3cbb60e
Compare
@alexcjohnson I tried to follow your lead but I got an error:
and it seems like this error comes from Maybe because I'm calling I tried different solution and it seems like it's working fine. Could you take a look? Not sure if it's the right one though... |
.then(done); | ||
}); | ||
|
||
xit('should return a resolved promise and purge plotly attributes - tmp', function(done) { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@alexcjohnson you would have to enable it to see the error
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Playing with this a little... I think this version of the test is correct, and what's needed is just to interpret the comment in the code // return if there is nothing to resize
a little more broadly - if the plot has been purged (in which case it has no layout
) that's another "nothing to resize." So perhaps:
if(!gd.layout || (gd.layout.width && gd.layout.height)) {
Which, at least if I run it in the console (Plotly.Plots.resize(gd);Plotly.purge(gd);
) successfully avoids throwing an error.
Hmm, it also occurs to me, looking at the code, we should bail out if isHidden(gd)
as well, ie when resize
was called the plot was visible, but before _redrawTimer
fired it has been hidden/removed. That's yet another "nothing to resize." So I guess:
if(!gd.layout || (gd.layout.width && gd.layout.height) || isHidden(gd)) {
The only other test we do outside _redrawTimer
is !gd
, but I don't see any way gd
could be truthy before and falsy 100ms later, it's still going to be a DOM element, the worst that can happen is it gets detached; so I think that should do it!
b4c5a1d
to
002bb16
Compare
002bb16
to
1d75ed1
Compare
@alexcjohnson done. I added additional code which handles early return (it still returns |
Beautiful, thanks @rafalbromirski! 💃 |
Lovely tests @rafalbromirski Thanks very much! |
While working with
plotly
&react-plotly
, from time to time I could notice minor error in my console:First, I thought the error is somewhere on my side but later it was clear it was inside
plotly
library. I backtracked the error and ended up here:=> https://github.com/plotly/plotly.js/blob/master/src/plots/plots.js#L75-L113
Reproducing it was possible by changing my routes faster than usual – not waiting for plotly to finish rendering charts – chaos monkey style. Apparently when you delete DOM node from your HTML,
gd
variables still holds the reference to the element which doesn't exist anymore. In that case if you try to callgd.layout.width/height
it will throw an error becauselayout
isundefined
.How to reproduce it:
npm start
gd
element:If you call
gd
, it still points to#graph
: