@@ -970,8 +970,10 @@ const createScatterplot = (initialProperties = {}) => {
970970 const setHeight = ( newHeight ) => {
971971 if ( newHeight === 'auto' ) {
972972 height = newHeight ;
973- setCurrentHeight ( canvas . getBoundingClientRect ( ) . height ) ;
974973 canvas . style . height = '100%' ;
974+ window . requestAnimationFrame ( ( ) => {
975+ if ( canvas ) setCurrentHeight ( canvas . getBoundingClientRect ( ) . height ) ;
976+ } ) ;
975977 return ;
976978 }
977979
@@ -1024,8 +1026,10 @@ const createScatterplot = (initialProperties = {}) => {
10241026 const setWidth = ( newWidth ) => {
10251027 if ( newWidth === 'auto' ) {
10261028 width = newWidth ;
1027- setCurrentWidth ( canvas . getBoundingClientRect ( ) . width ) ;
10281029 canvas . style . width = '100%' ;
1030+ window . requestAnimationFrame ( ( ) => {
1031+ if ( canvas ) setCurrentWidth ( canvas . getBoundingClientRect ( ) . width ) ;
1032+ } ) ;
10291033 return ;
10301034 }
10311035
@@ -2429,9 +2433,16 @@ const createScatterplot = (initialProperties = {}) => {
24292433 setDeselectOnEscape ( properties . deselectOnEscape ) ;
24302434 }
24312435
2432- updateViewAspectRatio ( ) ;
2433- refresh ( ) ;
2434- drawRaf ( ) ;
2436+ // setWidth and setHeight can be async when width or height are set to
2437+ // 'auto'. And since draw() would have anyway been async we can just make
2438+ // all calls async.
2439+ window . requestAnimationFrame ( ( ) => {
2440+ if ( ! canvas ) return ; // Instance was destroyed in between
2441+ updateViewAspectRatio ( ) ;
2442+ refresh ( ) ;
2443+ draw ( ) ;
2444+ drawHandler ( ) ;
2445+ } ) ;
24352446 } ;
24362447
24372448 const hover = ( point , showRecticleOnce = false ) => {
0 commit comments