@@ -113,29 +113,32 @@ class IPyWidgetOutput extends Shiny.OutputBinding {
113
113
this . _maybeResize ( lmWidget ) ;
114
114
}
115
115
_maybeResize ( lmWidget : HTMLElement ) : void {
116
- const impl = lmWidget . children [ 0 ] ;
117
- if ( impl . children . length > 0 ) {
118
- return this . _doResize ( impl ) ;
116
+ if ( this . _hasImplementation ( lmWidget ) ) {
117
+ return this . _doResize ( ) ;
119
118
}
120
119
121
120
// Some widget implementation (e.g., ipyleaflet, pydeck) won't actually
122
121
// have rendered to the DOM at this point, so wait until they do
123
122
const mo = new MutationObserver ( ( mutations ) => {
124
- if ( impl . children . length > 0 ) {
123
+ if ( this . _hasImplementation ( lmWidget ) ) {
125
124
mo . disconnect ( ) ;
126
- this . _doResize ( impl ) ;
125
+ this . _doResize ( ) ;
127
126
}
128
127
} ) ;
129
128
130
- mo . observe ( impl , { childList : true } ) ;
129
+ mo . observe ( lmWidget , { childList : true } ) ;
131
130
}
132
- _doResize ( impl : Element ) : void {
131
+ _doResize ( ) : void {
133
132
// Trigger resize event to force layout (setTimeout() is needed for altair)
134
133
// TODO: debounce this call?
135
134
setTimeout ( ( ) => {
136
135
window . dispatchEvent ( new Event ( 'resize' ) )
137
136
} , 0 ) ;
138
137
}
138
+ _hasImplementation ( lmWidget : HTMLElement ) : boolean {
139
+ const impl = lmWidget . children [ 0 ] ;
140
+ return impl && impl . children . length > 0 ;
141
+ }
139
142
}
140
143
141
144
Shiny . outputBindings . register ( new IPyWidgetOutput ( ) , "shiny.IPyWidgetOutput" ) ;
0 commit comments