@@ -455,9 +455,17 @@ export class WidgetManager extends LabWidgetManager {
455
455
*/
456
456
private _saveState ( ) : void {
457
457
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
+ }
461
469
}
462
470
463
471
_handleKernelConnectionStatusChange ( status : Kernel . ConnectionStatus ) : void {
@@ -512,7 +520,11 @@ export class WidgetManager extends LabWidgetManager {
512
520
* Load widget state from notebook metadata
513
521
*/
514
522
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' ) ;
516
528
// Restore any widgets from saved state that are not live
517
529
if ( widget_md && widget_md [ WIDGET_STATE_MIMETYPE ] ) {
518
530
let state = widget_md [ WIDGET_STATE_MIMETYPE ] ;
0 commit comments