Allow init_notebook_mode to redefine/reinitialize plotly.js each time it's run #1452
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Work towards addressing #1448
I don't think this addresses the root of the problem, but hopefully it will make it possible for users to call
init_notebook_mode
to reinitialize plotly.js in the notebook after the issue appears.I haven't been able to reproduce the error message naturally, but after some research an experimenting it looks like what's happening is that for some reason the requirejs infrastructure is forgetting that a library called
plotly
has beendefine
d (which happens ininit_notebook_mode
). I can force the same error by manually callingrequire.undef('plotly')
in the JavaScript console and then runningiplot
again.I don't have any leads at this point on what might be causing
requirejs
to "forget" about a registered module.But this PR updates the
init_nodebook_mode
logic to take this possibility into account. Now, every timeinit_notebook_mode
is called the 'plotly' module is explicitly undefined and redefined and thewindow._Plotly
variable is reinitialized.Now, when I invoke the error state by calling
require.undef('plotly')
I can at least recover from it by runninginit_notebook_mode()
a second time. Before this PR we would get stuck in a state where the requirejs 'plotly' module was undefined but thewindow._Plotly
variable was still set and soinit_notebook_mode
would skip redefining the 'plotly' module.