@@ -7,7 +7,7 @@ import { JupyterLuminoPanelWidget } from '@jupyter-widgets/base';
77
88import { Panel } from '@lumino/widgets' ;
99
10- import { WidgetManager } from './manager' ;
10+ import { LabWidgetManager , WidgetManager } from './manager' ;
1111
1212import { OutputAreaModel , OutputArea } from '@jupyterlab/outputarea' ;
1313
@@ -33,11 +33,14 @@ export class OutputModel extends outputBase.OutputModel {
3333 return false ;
3434 } ;
3535
36- this . widget_manager . context . sessionContext . kernelChanged . connect (
37- ( sender , args ) => {
38- this . _handleKernelChanged ( args ) ;
39- }
40- ) ;
36+ // if the context is available, react on kernel changes
37+ if ( this . widget_manager instanceof WidgetManager ) {
38+ this . widget_manager . context . sessionContext . kernelChanged . connect (
39+ ( sender , args ) => {
40+ this . _handleKernelChanged ( args ) ;
41+ }
42+ ) ;
43+ }
4144 this . listenTo ( this , 'change:msg_id' , this . reset_msg_id ) ;
4245 this . listenTo ( this , 'change:outputs' , this . setOutputs ) ;
4346 this . setOutputs ( ) ;
@@ -60,7 +63,7 @@ export class OutputModel extends outputBase.OutputModel {
6063 * Reset the message id.
6164 */
6265 reset_msg_id ( ) : void {
63- const kernel = this . widget_manager . context . sessionContext ?. session ?. kernel ;
66+ const kernel = this . widget_manager . kernel ;
6467 const msgId = this . get ( 'msg_id' ) ;
6568 const oldMsgId = this . previous ( 'msg_id' ) ;
6669
@@ -114,7 +117,7 @@ export class OutputModel extends outputBase.OutputModel {
114117 }
115118 }
116119
117- widget_manager : WidgetManager ;
120+ widget_manager : LabWidgetManager ;
118121
119122 private _msgHook : ( msg : KernelMessage . IIOPubMessage ) => boolean ;
120123 private _outputs : OutputAreaModel ;
0 commit comments