@@ -240,7 +240,13 @@ export class IpywidgetsState extends EventEmitter {
240
240
}
241
241
const f = async ( path : string ) => {
242
242
const hash = value ?. get ( path ) ;
243
- if ( hash == null ) return ;
243
+ if ( ! hash ) {
244
+ // It is important to look for !hash, since we use hash='' as a sentinel (in this.clearOutputBuffers)
245
+ // to indicate that we want to consider a buffer as having been deleted. This is very important
246
+ // to do since large outputs are often buffers in output widgets, and clear_output
247
+ // then needs to delete those buffers, or output never goes away.
248
+ return ;
249
+ }
244
250
const cur = this . arrayBuffers [ model_id ] [ path ] ;
245
251
if ( cur ?. hash == hash ) {
246
252
buffer_paths . push ( JSON . parse ( path ) ) ;
@@ -741,7 +747,7 @@ export class IpywidgetsState extends EventEmitter {
741
747
this . clear_output [ model_id ] = true ;
742
748
} else {
743
749
delete this . clear_output [ model_id ] ;
744
- this . clearOutputBuffers ( ) ;
750
+ this . clearOutputBuffers ( model_id ) ;
745
751
this . set_model_value ( model_id , { outputs : null } ) ;
746
752
}
747
753
return true ;
@@ -755,7 +761,7 @@ export class IpywidgetsState extends EventEmitter {
755
761
let outputs : any ;
756
762
if ( this . clear_output [ model_id ] ) {
757
763
delete this . clear_output [ model_id ] ;
758
- this . clearOutputBuffers ( ) ;
764
+ this . clearOutputBuffers ( model_id ) ;
759
765
outputs = [ ] ;
760
766
} else {
761
767
outputs = this . get_model_value ( model_id ) . outputs ;
@@ -768,7 +774,7 @@ export class IpywidgetsState extends EventEmitter {
768
774
return true ;
769
775
} ;
770
776
771
- private clearOutputBuffers = ( ) => {
777
+ private clearOutputBuffers = ( model_id : string ) => {
772
778
// TODO: need to clear all output buffers.
773
779
/* Example where if you do not properly clear buffers, then broken output re-appears:
774
780
@@ -789,6 +795,21 @@ with out:
789
795
print('hi')
790
796
*/
791
797
// TODO!!!!
798
+
799
+ const y : any = { } ;
800
+ let n = 0 ;
801
+ for ( const jsonPath of this . get ( model_id , "buffers" ) ?. keySeq ( ) ?? [ ] ) {
802
+ const path = JSON . parse ( jsonPath ) ;
803
+ console . log ( "path = " , path ) ;
804
+ if ( path [ 0 ] == "outputs" ) {
805
+ y [ jsonPath ] = "" ;
806
+ n += 1 ;
807
+ }
808
+ }
809
+ console . log ( "y = " , y ) ;
810
+ if ( n > 0 ) {
811
+ this . set ( model_id , "buffers" , y , true , "shallow" ) ;
812
+ }
792
813
} ;
793
814
794
815
private sendCustomMessage = async (
0 commit comments