11import type * as monaco from "monaco-editor" ;
2- import { Component , createRef } from "react" ;
2+ import { Component , createRef , lazy , Suspense } from "react" ;
33import { ErrorBoundary } from "react-error-boundary" ;
4+ import { BarLoader } from "react-spinners" ;
45import SplitPane from "react-split-pane" ;
56
67import { getSplitConfig , saveSplitConfig } from "../config.js" ;
78import type { SupportedEngine , SupportedFormat } from "../rendering.js" ;
8- import Editor from "./Editor.js" ;
99import type EditorPane from "./EditorPane.js" ;
10- import GraphPane from "./GraphPane.js" ;
10+
11+ const EditorLazy = lazy ( ( ) => import ( "./Editor.js" ) ) ;
12+ const GraphPaneLazy = lazy ( ( ) => import ( "./GraphPane.js" ) ) ;
1113
1214type ErrorList = monaco . editor . IMarkerData [ ] ;
1315
@@ -30,6 +32,14 @@ type ErroredState = {
3032 lastKnownGoodSrc ?: string ;
3133} ;
3234
35+ const loadingStyle = {
36+ position : "absolute" ,
37+ display : "flex" ,
38+ inset : "0" ,
39+ justifyContent : "center" ,
40+ alignItems : "center" ,
41+ } as const ;
42+
3343export default class SplitEditor extends Component <
3444 SplitEditorProps ,
3545 SplitEditorState
@@ -94,19 +104,35 @@ export default class SplitEditor extends Component<
94104 { ...( { } as any ) }
95105 >
96106 < ErrorBoundary fallback = "Could not load editor" >
97- < Editor
98- initialValue = { s . dotSrc }
99- onChangeValue = { ( ) => [ ] }
100- onValueError = { n => void n }
101- />
107+ < Suspense
108+ fallback = {
109+ < div style = { loadingStyle } >
110+ < BarLoader />
111+ </ div >
112+ }
113+ >
114+ < EditorLazy
115+ initialValue = { s . dotSrc }
116+ onChangeValue = { ( ) => [ ] }
117+ onValueError = { n => void n }
118+ />
119+ </ Suspense >
102120 </ ErrorBoundary >
103121 < ErrorBoundary fallback = "Could not load graph preview" >
104- < GraphPane
105- hasErrors = { ! ! ( s . errors && s . errors . length > 0 ) }
106- dotSrc = { dotSrc }
107- engine = { p . engine }
108- format = { p . format }
109- />
122+ < Suspense
123+ fallback = {
124+ < div style = { loadingStyle } >
125+ < BarLoader />
126+ </ div >
127+ }
128+ >
129+ < GraphPaneLazy
130+ hasErrors = { ! ! ( s . errors && s . errors . length > 0 ) }
131+ dotSrc = { dotSrc }
132+ engine = { p . engine }
133+ format = { p . format }
134+ />
135+ </ Suspense >
110136 </ ErrorBoundary >
111137 </ SplitPane >
112138 ) ;
0 commit comments