@@ -455,9 +455,17 @@ export class WidgetManager extends LabWidgetManager {
455455 */
456456 private _saveState ( ) : void {
457457 const state = this . get_state_sync ( { drop_defaults : true } ) ;
458- this . _context . model . setMetadata ( 'widgets' , {
459- 'application/vnd.jupyter.widget-state+json' : state ,
460- } ) ;
458+ if ( this . _context . model . setMetadata ) {
459+ this . _context . model . setMetadata ( 'widgets' , {
460+ 'application/vnd.jupyter.widget-state+json' : state ,
461+ } ) ;
462+ } else {
463+ // eslint-disable-next-line @typescript-eslint/ban-ts-comment
464+ // @ts -ignore JupyterLab 3 support
465+ this . _context . model . metadata . set ( 'widgets' , {
466+ 'application/vnd.jupyter.widget-state+json' : state ,
467+ } ) ;
468+ }
461469 }
462470
463471 _handleKernelConnectionStatusChange ( status : Kernel . ConnectionStatus ) : void {
@@ -512,7 +520,11 @@ export class WidgetManager extends LabWidgetManager {
512520 * Load widget state from notebook metadata
513521 */
514522 async _loadFromNotebook ( notebook : INotebookModel ) : Promise < void > {
515- const widget_md = notebook . getMetadata ( 'widgets' ) as any ;
523+ const widget_md = notebook . getMetadata
524+ ? ( notebook . getMetadata ( 'widgets' ) as any )
525+ : // eslint-disable-next-line @typescript-eslint/ban-ts-comment
526+ // @ts -ignore JupyterLab 3 support
527+ notebook . metadata . get ( 'widgets' ) ;
516528 // Restore any widgets from saved state that are not live
517529 if ( widget_md && widget_md [ WIDGET_STATE_MIMETYPE ] ) {
518530 let state = widget_md [ WIDGET_STATE_MIMETYPE ] ;
0 commit comments