As @etpinard pointed out during the finance refactor PR #2561 (comment) and #2561 (comment) we have a mess when redrawing cartesian SVG traces, both re: deleting and redrawing existing traces and re: removing completely unused modules.
The first part we can handle by making all the trace modules support more d3-idiomatic enter/exit/each logic as suggested in this TODO. The second has a few ways to go about it. Quoting @etpinard:
What we need to do is find all the gone modules (i.e. modules with had??=true and has??=false), loop over them, and then do what we need to do the cleanup the DOM.
Better yet -- as more and more trace type will follow scatter and ohlc in not expecting a selectAll('g.trace').remove() before each _module.plot() -- we could add a trace module method (maybe called cleanDOM) to each trace modules that need to remove things for the DOM (or destroy WebGL objects).
To note, geo subplots (and maybe others?) solve this problem in a different way by using Plots.generalUpdatePerTraceModule which calls _module.plot of visible and gone modules and expects the trace module plot methods to clean up the DOM accordingly (e.g. like here for choropleth traces). At present though, I think adding cleanDOM to each trace module would be best, as it would allow us to handle the scattergl and range-slider cases more easily.
As @etpinard pointed out during the finance refactor PR #2561 (comment) and #2561 (comment) we have a mess when redrawing cartesian SVG traces, both re: deleting and redrawing existing traces and re: removing completely unused modules.
The first part we can handle by making all the trace modules support more d3-idiomatic
enter/exit/eachlogic as suggested in this TODO. The second has a few ways to go about it. Quoting @etpinard: