File tree Expand file tree Collapse file tree 4 files changed +47
-11
lines changed
src/packages/frontend/frame-editors
whiteboard-editor/elements/code Expand file tree Collapse file tree 4 files changed +47
-11
lines changed Original file line number Diff line number Diff line change @@ -1636,8 +1636,15 @@ export class Actions<
1636
1636
}
1637
1637
1638
1638
if ( this . _syncstring . get_state ( ) != "ready" ) {
1639
- await once ( this . _syncstring , "ready" ) ;
1640
- if ( this . isClosed ( ) ) return ;
1639
+ try {
1640
+ await once ( this . _syncstring , "ready" ) ;
1641
+ } catch {
1642
+ // never made it
1643
+ return ;
1644
+ }
1645
+ if ( this . isClosed ( ) ) {
1646
+ return ;
1647
+ }
1641
1648
}
1642
1649
1643
1650
// NOTE: we fallback to getting the underlying CM doc, in case all actual
@@ -1751,7 +1758,12 @@ export class Actions<
1751
1758
const state = syncdoc . get_state ( ) ;
1752
1759
if ( state == "closed" ) return false ;
1753
1760
if ( state == "init" ) {
1754
- await once ( syncdoc , "ready" ) ;
1761
+ try {
1762
+ await once ( syncdoc , "ready" ) ;
1763
+ } catch {
1764
+ // never mode it
1765
+ return false ;
1766
+ }
1755
1767
if ( this . isClosed ( ) ) return false ;
1756
1768
}
1757
1769
return true ;
Original file line number Diff line number Diff line change @@ -260,9 +260,16 @@ export class Actions extends BaseActions<LatexEditorState> {
260
260
261
261
// Wait until the syncstring is loaded from disk.
262
262
if ( this . _syncstring . get_state ( ) == "init" ) {
263
- await once ( this . _syncstring , "ready" ) ;
263
+ try {
264
+ await once ( this . _syncstring , "ready" ) ;
265
+ } catch {
266
+ // closed before finished opening
267
+ return ;
268
+ }
269
+ }
270
+ if ( this . _state == "closed" ) {
271
+ return ;
264
272
}
265
- if ( this . _state == "closed" ) return ;
266
273
267
274
let program = "" ; // later, might contain the !TeX program build directive
268
275
let cocalc_cmd = "" ; // later, might contain the cocalc command
@@ -327,9 +334,16 @@ export class Actions extends BaseActions<LatexEditorState> {
327
334
this . _init_syncdb ( [ "key" ] , undefined , path ) ;
328
335
329
336
// Wait for the syncdb to be loaded and ready.
330
- if ( this . _syncdb == null ) throw Error ( "syncdb must be defined" ) ;
337
+ if ( this . _syncdb == null ) {
338
+ throw Error ( "syncdb must be defined" ) ;
339
+ }
331
340
if ( this . _syncdb . get_state ( ) == "init" ) {
332
- await once ( this . _syncdb , "ready" ) ;
341
+ try {
342
+ await once ( this . _syncdb , "ready" ) ;
343
+ } catch {
344
+ // user closed it
345
+ return ;
346
+ }
333
347
if ( this . _state == "closed" ) return ;
334
348
}
335
349
Original file line number Diff line number Diff line change @@ -140,7 +140,11 @@ export class TimeTravelActions extends CodeEditorActions<TimeTravelState> {
140
140
if ( this . syncdoc == null ) return ;
141
141
this . syncdoc . on ( "change" , debounce ( this . syncdoc_changed , 1000 ) ) ;
142
142
if ( this . syncdoc . get_state ( ) != "ready" ) {
143
- await once ( this . syncdoc , "ready" ) ;
143
+ try {
144
+ await once ( this . syncdoc , "ready" ) ;
145
+ } catch {
146
+ return ;
147
+ }
144
148
}
145
149
if ( this . syncdoc == null ) return ;
146
150
// cause initial load -- we could be plugging into an already loaded syncdoc,
Original file line number Diff line number Diff line change @@ -54,7 +54,13 @@ export default function Code({
54
54
const [ mode , setMode ] = useState < any > ( codemirrorMode ( "py" ) ) ;
55
55
const isMountedRef = useIsMountedRef ( ) ;
56
56
useAsyncEffect ( async ( ) => {
57
- const mode = await getMode ( { project_id, path } ) ;
57
+ let mode ;
58
+ try {
59
+ mode = await getMode ( { project_id, path } ) ;
60
+ } catch {
61
+ // this can fail, e.g., if user closes file before finishing opening it
62
+ return ;
63
+ }
58
64
if ( isMountedRef . current ) {
59
65
setMode ( mode ) ;
60
66
}
@@ -100,7 +106,7 @@ export default function Code({
100
106
if ( elt == null ) return ;
101
107
const h = Math . max (
102
108
MIN_HEIGHT ,
103
- elt . getBoundingClientRect ( ) ?. height / canvasScale + EXTRA_HEIGHT
109
+ elt . getBoundingClientRect ( ) ?. height / canvasScale + EXTRA_HEIGHT ,
104
110
) ;
105
111
actions . setElement ( {
106
112
obj : { id : element . id , h } ,
@@ -116,7 +122,7 @@ export default function Code({
116
122
if ( elt == null ) return ;
117
123
const newHeight = Math . max (
118
124
MIN_HEIGHT ,
119
- elt . getBoundingClientRect ( ) ?. height / canvasScale + EXTRA_HEIGHT
125
+ elt . getBoundingClientRect ( ) ?. height / canvasScale + EXTRA_HEIGHT ,
120
126
) ;
121
127
if ( newHeight > element . h ) {
122
128
shrinkElement . cancel ( ) ;
You can’t perform that action at this time.
0 commit comments