@@ -444,7 +444,7 @@ export abstract class LabWidgetManager extends ManagerBase<Widget>
444
444
445
445
protected _restored = new Signal < this, void > ( this ) ;
446
446
protected _restoredStatus = false ;
447
- protected _initialRestoredStatus = false ;
447
+ protected _kernelRestoreInProgress = false ;
448
448
449
449
private _isDisposed = false ;
450
450
private _registry : SemVerCache < ExportData > = new SemVerCache < ExportData > ( ) ;
@@ -487,9 +487,9 @@ export class KernelWidgetManager extends LabWidgetManager {
487
487
488
488
_handleKernelConnectionStatusChange ( status : Kernel . ConnectionStatus ) : void {
489
489
if ( status === 'connected' ) {
490
- // Only restore if our initial restore at construction is finished
491
- if ( this . _initialRestoredStatus ) {
492
- // We only want to restore widgets from the kernel, not ones saved in the notebook.
490
+ // Only restore if we aren't currently trying to restore from the kernel
491
+ // (for example, in our initial restore from the constructor).
492
+ if ( ! this . _kernelRestoreInProgress ) {
493
493
this . restoreWidgets ( ) ;
494
494
}
495
495
}
@@ -506,13 +506,14 @@ export class KernelWidgetManager extends LabWidgetManager {
506
506
*/
507
507
async restoreWidgets ( ) : Promise < void > {
508
508
try {
509
+ this . _kernelRestoreInProgress = true ;
509
510
await this . _loadFromKernel ( ) ;
510
511
this . _restoredStatus = true ;
511
- this . _initialRestoredStatus = true ;
512
512
this . _restored . emit ( ) ;
513
513
} catch ( err ) {
514
514
// Do nothing
515
515
}
516
+ this . _kernelRestoreInProgress = false ;
516
517
}
517
518
518
519
/**
@@ -588,8 +589,9 @@ export class WidgetManager extends LabWidgetManager {
588
589
589
590
_handleKernelConnectionStatusChange ( status : Kernel . ConnectionStatus ) : void {
590
591
if ( status === 'connected' ) {
591
- // Only restore if our initial restore at construction is finished
592
- if ( this . _initialRestoredStatus ) {
592
+ // Only restore if we aren't currently trying to restore from the kernel
593
+ // (for example, in our initial restore from the constructor).
594
+ if ( ! this . _kernelRestoreInProgress ) {
593
595
// We only want to restore widgets from the kernel, not ones saved in the notebook.
594
596
this . restoreWidgets ( this . _context ! . model , {
595
597
loadKernel : true ,
@@ -614,7 +616,12 @@ export class WidgetManager extends LabWidgetManager {
614
616
) : Promise < void > {
615
617
try {
616
618
if ( loadKernel ) {
617
- await this . _loadFromKernel ( ) ;
619
+ try {
620
+ this . _kernelRestoreInProgress = true ;
621
+ await this . _loadFromKernel ( ) ;
622
+ } finally {
623
+ this . _kernelRestoreInProgress = false ;
624
+ }
618
625
}
619
626
if ( loadNotebook ) {
620
627
await this . _loadFromNotebook ( notebook ) ;
@@ -626,9 +633,6 @@ export class WidgetManager extends LabWidgetManager {
626
633
} catch ( err ) {
627
634
// Do nothing if the restore did not work.
628
635
}
629
- // We *always* claim that the initial restore happened, so when we connect
630
- // to a kernel, we will initiate another restore. Maybe this should really be a "restore in progress" variable?
631
- this . _initialRestoredStatus = true ;
632
636
}
633
637
634
638
/**
0 commit comments