|
1 | | -import type { ReactNode } from 'react'; |
| 1 | +import { lazy, Suspense, type ReactNode } from 'react'; |
2 | 2 | import { activeTab, isDirty, useEditorStore } from '../editor/store'; |
3 | 3 | import { EditorTabs } from './EditorTabs'; |
4 | 4 | import { MenuSidebar } from './MenuSidebar'; |
5 | 5 | import { OutputPanel } from './OutputPanel'; |
6 | 6 | import { StatusBar } from './StatusBar'; |
7 | | -import { VisualEditor } from './visual/VisualEditor'; |
8 | | -import { FormBuilder } from './visual/FormBuilder'; |
9 | | -import { ConfigEditor } from './visual/ConfigEditor'; |
10 | | -import { YamlEditor } from './YamlEditor'; |
| 7 | + |
| 8 | +// Each of these pulls a heavy dependency (CodeMirror, the canvas, the form |
| 9 | +// builder), and only one of them is on screen at a time. |
| 10 | +const YamlEditor = lazy(() => import('./YamlEditor').then(m => ({ default: m.YamlEditor }))); |
| 11 | +const VisualEditor = lazy(() => import('./visual/VisualEditor').then(m => ({ default: m.VisualEditor }))); |
| 12 | +const FormBuilder = lazy(() => import('./visual/FormBuilder').then(m => ({ default: m.FormBuilder }))); |
| 13 | +const ConfigEditor = lazy(() => import('./visual/ConfigEditor').then(m => ({ default: m.ConfigEditor }))); |
11 | 14 | import type { MenuDiagnostics } from '../editor/validator'; |
12 | 15 | import type { MenuDescriptor } from '../types/editor'; |
13 | 16 |
|
@@ -137,6 +140,7 @@ export function WorkspaceLayout({ |
137 | 140 |
|
138 | 141 | <div className="editor-content"> |
139 | 142 | <div className="editor-body"> |
| 143 | + <Suspense fallback={<div className="item-editor-content">Loading the editor...</div>}> |
140 | 144 | {current === null ? ( |
141 | 145 | <div className="welcome-screen"> |
142 | 146 | <div className="welcome-icon">📝</div> |
@@ -168,6 +172,7 @@ export function WorkspaceLayout({ |
168 | 172 | onChange={content => dispatch({ type: 'tab/edited', key: current.key, content })} |
169 | 173 | /> |
170 | 174 | )} |
| 175 | + </Suspense> |
171 | 176 | </div> |
172 | 177 |
|
173 | 178 | <OutputPanel diagnostics={diagnostics} onClose={onCloseDiagnostics} /> |
|
0 commit comments