forked from argoproj/argo-workflows
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
refactor(ui): code-split gigantic Monaco Editor dep (argoproj#12150)
Signed-off-by: Anton Gilgur <agilgur5@gmail.com>
- Loading branch information
Showing
5 changed files
with
67 additions
and
32 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,22 @@ | ||
import * as React from 'react'; | ||
import {MonacoEditorProps} from 'react-monaco-editor'; | ||
import MonacoEditor from 'react-monaco-editor'; | ||
|
||
import {Loading} from './loading'; | ||
|
||
// lazy load Monaco Editor as it is a gigantic component (which can be split into a separate bundle) | ||
const LazyMonacoEditor = React.lazy(() => { | ||
return import(/* webpackChunkName: "react-monaco-editor" */ 'react-monaco-editor'); | ||
}); | ||
|
||
// workaround, react-monaco-editor's own default no-op seems to fail when lazy loaded, causing a crash when unmounted | ||
// react-monaco-editor's default no-op: https://github.com/react-monaco-editor/react-monaco-editor/blob/7e5a4938cd328bf95ebc1288967f2037c6023b5a/src/editor.tsx#L184 | ||
const noop = () => {}; // tslint:disable-line:no-empty | ||
|
||
export const SuspenseMonacoEditor = React.forwardRef(function InnerMonacoEditor(props: MonacoEditorProps, ref: React.MutableRefObject<MonacoEditor>) { | ||
return ( | ||
<React.Suspense fallback={<Loading />}> | ||
<LazyMonacoEditor ref={ref} editorWillUnmount={noop} {...props} /> | ||
</React.Suspense> | ||
); | ||
}); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters