{"record":{"id":"ba7b20ae6e773ede","repo":"plotly/plotly.js","slug":"calling-doplot-as-if-redrawing-but-this-container","errorCode":null,"errorMessage":"Calling _doPlot as if redrawing but this container doesn't yet have a plot.","messagePattern":"Calling _doPlot as if redrawing but this container doesn't yet have a plot\\.","errorType":"console","errorClass":null,"httpStatus":null,"severity":"warning","filePath":"src/plot_api/plot_api.js","lineNumber":81,"sourceCode":"\n    // Events.init is idempotent and bails early if gd has already been init'd\n    Events.init(gd);\n\n    if (Lib.isPlainObject(data)) {\n        var obj = data;\n        data = obj.data;\n        layout = obj.layout;\n        config = obj.config;\n        frames = obj.frames;\n    }\n\n    var okToPlot = Events.triggerHandler(gd, 'plotly_beforeplot', [data, layout, config]);\n    if (okToPlot === false) return Promise.reject();\n\n    // if there's no data or layout, and this isn't yet a plotly plot\n    // container, log a warning to help plotly.js users debug\n    if (!data && !layout && !Lib.isPlotDiv(gd)) {\n        Lib.warn('Calling _doPlot as if redrawing ' + \"but this container doesn't yet have a plot.\", gd);\n    }\n\n    function addFrames() {\n        if (frames) {\n            return exports.addFrames(gd, frames);\n        }\n    }\n\n    // transfer configuration options to gd until we move over to\n    // a more OO like model\n    setPlotContext(gd, config);\n\n    if (!layout) layout = {};\n\n    // hook class for plots main container (in case of plotly.js\n    // this won't be #embedded-graph or .js-tab-contents)\n    d3.select(gd).classed('js-plotly-plot', true);\n","sourceCodeStart":63,"sourceCodeEnd":99,"githubUrl":"https://github.com/plotly/plotly.js/blob/1d090e0b5ffb8d0fdf6e0e4ff51d3f3cf67f1314/src/plot_api/plot_api.js#L63-L99","documentation":"Plotly.react/Plotly.newPlot funnel into _doPlot. If neither data nor layout is passed and the graph div was never plotted (no gd._fullLayout / plot context), the call is effectively a 'redraw' of nothing, so plotly.js logs this warning and skips plotting instead of crashing.","triggerScenarios":"Plotly.redraw(gd) or Plotly.relayout/Plotly.restyle with no data/layout changes on a div where Plotly.newPlot/Plotly.react never succeeded; calling Plotly.redraw on an empty <div> or before the async newPlot promise resolved.","commonSituations":"Calling Plotly.redraw() inside framework lifecycle hooks (React useEffect / Angular ngAfterViewInit) before the plot exists; redraw after a failed newPlot; grabbing the wrong DOM element id so the div was never plotted; render loops triggered before async plot initialization completes.","solutions":["Call Plotly.newPlot(gd, data, layout) (or Plotly.react) first, and only redraw after its promise resolves","Check the div was actually plotted, e.g. gd._fullLayout exists or Plotly.d3.select(gd).selectAll('.plotly').size() > 0, before calling redraw","Ensure data and/or layout is passed when you intend to plot, since redraw only re-renders an existing plot","Verify you selected the correct graph div id; a missing element silently yields an unplotted container","If using React, await Plotly.newPlot before triggering state-driven redraws"],"exampleFix":"// before\nconst gd = document.getElementById('graph');\nPlotly.redraw(gd);\n// after\nPlotly.newPlot(gd, data, layout).then(() => Plotly.redraw(gd));","handlingStrategy":"validation","validationCode":"function isPlotted(gd) {\n  return !!(gd && gd._fullLayout && gd._fullLayout._uid && gd.data);\n}\nif (!isPlotted(gd)) { await Plotly.newPlot(gd, data, layout); } else { Plotly.redraw(gd); }","typeGuard":"function isPlotDiv(gd) { return !!(gd && gd.classList && gd.classList.contains('js-plotly-plot')); }","tryCatchPattern":null,"preventionTips":["Always initialize with Plotly.newPlot and redraw only after the promise resolves","Check gd.classList contains 'js-plotly-plot' before redraw","Avoid calling redraw for containers that only got Plotly.purge or failed to plot","In frameworks, gate redraw calls behind a 'plotReady' flag set after newPlot"],"tags":["lifecycle","redraw","initialization"],"backgroundTag":"plot-before-initialization","analyzedSha":"1d090e0b5ffb8d0fdf6e0e4ff51d3f3cf67f1314","analyzedAt":"2026-09-02T22:03:39.906Z","contentChangedAt":null,"schemaVersion":2},"datasetVersion":"2026-09-10T02:17:09.455Z"}