@@ -5,6 +5,7 @@ import { Prompt } from 'react-router-dom';
55import { reaction } from 'mobx' ;
66import { TextOperation } from 'ot' ;
77import { inject , observer } from 'mobx-react' ;
8+ import { debounce } from 'lodash-es' ;
89
910import getTemplateDefinition from 'common/lib/templates' ;
1011import type { ModuleError } from 'common/lib/types' ;
@@ -63,6 +64,8 @@ class EditorPreview extends React.Component<Props, State> {
6364 ( ) => this . forceUpdate ( )
6465 ) ;
6566
67+ this . getBounds = debounce ( this . getBoundsInstantly , 100 ) ;
68+
6669 window . addEventListener ( 'resize' , this . getBounds ) ;
6770
6871 this . interval = setInterval ( ( ) => {
@@ -84,13 +87,12 @@ class EditorPreview extends React.Component<Props, State> {
8487 }
8588 }
8689
87- getBounds = el => {
90+ getBoundsInstantly = el => {
8891 if ( el ) {
8992 this . el = this . el || el ;
9093 }
9194 if ( this . el ) {
9295 const { width, height } = this . el . getBoundingClientRect ( ) ;
93-
9496 if ( width !== this . state . width || height !== this . state . height ) {
9597 this . setState ( { width, height } ) ;
9698 }
@@ -329,7 +331,7 @@ class EditorPreview extends React.Component<Props, State> {
329331 ( ) => this . props . store . editor . previewWindowVisible ,
330332 ( ) => {
331333 requestAnimationFrame ( ( ) => {
332- this . getBounds ( ) ;
334+ this . getBoundsInstantly ( ) ;
333335 } ) ;
334336 }
335337 ) ;
@@ -553,7 +555,7 @@ class EditorPreview extends React.Component<Props, State> {
553555 } }
554556 >
555557 < div
556- ref = { this . getBounds }
558+ ref = { this . getBoundsInstantly }
557559 style = { {
558560 position : 'relative' ,
559561 display : 'flex' ,
@@ -575,8 +577,6 @@ class EditorPreview extends React.Component<Props, State> {
575577 isModuleSynced = { store . editor . isModuleSynced }
576578 width = { editorWidth }
577579 height = { editorHeight }
578- absoluteWidth = { absoluteWidth }
579- absoluteHeight = { absoluteHeight }
580580 settings = { settings ( store ) }
581581 sendTransforms = { this . sendTransforms }
582582 readOnly = { isReadOnly ( ) }
0 commit comments