'TypeError: e is undefined' when using Plotly.relayout followed by Plotly.purge

This may be a user error, but I have no idea what I am doing wrong. I’m trying to return to the default x and y axis range before purging the plot so that when the plot is opened again, the x and y axis ranges correspond to the new trace being plotted. Currently, if I plot a trace, manually drag the axis ranges slightly off, and then purge the plot and try to plot another trace in
the same div, the x and y axis ranges remain as they did after I manually changed them.

Here is the code:
var update = {
‘yaxis.rangemode’: “tozero”,
‘xaxis.type’: “date”
};
var newlayout = {
yaxis: {
rangemode: “tozero”
},
xaxis: {
type: “date”
}
};
Plotly.relayout(‘plotly-TS’, newlayout);
Plotly.purge(‘plotly-TS’);

This works as far as it does what I want it to do with resetting the axis ranges; however, I checked the console and I get
this error “`TypeError: e is undefined”.
I thought I was defining newlayout incorrectly and tried using update(as defined above) instead. When I do this, I get the same TypeError, and I do not get the desired behaviour with the plot range. The x and y axis ranges remain as they were when I manually drag them.

Am I doing something wrong? Or is there a different work around for my desired behaviour?

It seems there were some timing issues. I put in a 10ms wait before purging and now I do not receive an error.

Hmm, strange. Could you provide a fully reproducible example in a codepen / jsFiddle to help us figure out what’s wrong here? Thank you.

Here’s a link to a fiddle: https://jsfiddle.net/L9kch4zd/7/
After it loads, clicking Purge throws the TypeError.

@etienne Any updates/news regarding this?

Thanks for the jsFiddle!

Can I ask why you’re calling Plotly.relayout before Plotly.purge in your Clone handler?

Thanks for the response! I tried to explain in my original question, but I don’t think it was very clear.
I want to return the layout of the plot to the ‘default’ before purging, because otherwise if I make a new plot in the same div, the layout is the same as the previous layout, even if it does not match the current graph.
For example, in the jsFiddle:

  1. After it loads, drag the y-axis down do you are looking at a different range (ie. 5-9).
  2. Click ‘Purge’.
  3. Click ‘RePlot’.
    The new plot should have the correct axis ranges. However, running the same steps above without the Plotly.relayout before the Plotly.purge, does not reset the axis. You can see this by commenting out Plotly.relayout in line 58 and following the same steps as above.