ReferenceError: Plotly is not defined

I have a clientside callback that changes the size of a grid of plotly figures. it sets the height and width of each figure

      image_grid.forEach((gr, i) => {
        const figure = { layout: gr.layout };
        figure.layout.height = newSize;
        figure.layout.width = newSize;
        Plotly.react(gr, figure);

This code works fine in general but the first time it is triggered i get an error. After that it works fine

Any ideas why?

dash_renderer.v2_8_1m1675862663.min.js:2 ReferenceError: Plotly is not defined
    at grid_view_callbacks.…7602140.974067:63:9
    at Array.forEach (<anonymous>)
    at Object.update_plotly_images (grid_view_callbacks.…602140.974067:56:18)
    at dash_renderer.v2_8_1…663.min.js:2:123463
    at s (dash_renderer.v2_8_1…663.min.js:2:113472)
    at Generator._invoke (dash_renderer.v2_8_1…663.min.js:2:113225)
    at (dash_renderer.v2_8_1…663.min.js:2:113835)
    at pa (dash_renderer.v2_8_1…663.min.js:2:119413)
    at a (dash_renderer.v2_8_1…663.min.js:2:119617)
    at dash_renderer.v2_8_1…663.min.js:2:119678