Fix: Clear plotlyReadyCallbacks to prevent old callbacks from executing. #474
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.
This is a fix for issue #470. If using more than one chart on a page in a fast loading environment, such as a production environment, charts might fail to render on subsequent visits to the page.
Possible timeline:
First page visit:
Chart-1: Plotly might not be loaded -> calls end up in plotlyReadyCallback queue.
script.onload is fired, executing Chart1 callbacks and renders Chart-1.
Chart-2 is rendered directly since Plotly is loaded, which means no callbacks in queue.
Second page visit:
Chart-3: Since plotly is already loaded renders directly with no callbacks in queue.
script.onload is fired trying to execute callbacks for Chart-1 which does not exist and causes an uncaught exception.
Chart-4 is not rendered due to uncaught errors.
Note that the exceptions can still be thrown even with one plot on the page but mostly the chart is already rendered when the exception is thrown.