From d1e4c2c90d5af84917ac37f870bd84c6727a6e51 Mon Sep 17 00:00:00 2001 From: Nate Kelley Date: Mon, 10 Feb 2025 21:00:49 -0700 Subject: [PATCH] Update AppCodeEditor.tsx --- .../inputs/AppCodeEditor/AppCodeEditor.tsx | 41 +++++-------------- 1 file changed, 10 insertions(+), 31 deletions(-) diff --git a/web/src/components/inputs/AppCodeEditor/AppCodeEditor.tsx b/web/src/components/inputs/AppCodeEditor/AppCodeEditor.tsx index 30ebf1614..a02788aad 100644 --- a/web/src/components/inputs/AppCodeEditor/AppCodeEditor.tsx +++ b/web/src/components/inputs/AppCodeEditor/AppCodeEditor.tsx @@ -3,13 +3,11 @@ //https://github.com/popsql/monaco-sql-languages/blob/main/example/src/App.js#L2 //https://dtstack.github.io/monaco-sql-languages/ -import React, { forwardRef, useLayoutEffect, useMemo } from 'react'; +import React, { forwardRef, useMemo } from 'react'; import type { editor } from 'monaco-editor/esm/vs/editor/editor.api'; -import dynamic from 'next/dynamic'; import { CircleSpinnerLoaderContainer } from '../../loaders/CircleSpinnerLoaderContainer'; import { useBusterStylesContext } from '@/context/BusterStyles/BusterStyles'; import { createStyles } from 'antd-style'; -import { motion } from 'framer-motion'; import { useMemoizedFn } from 'ahooks'; import './MonacoWebWorker'; @@ -19,11 +17,7 @@ import { configureMonacoToUseYaml } from './yamlHelper'; //import NightOwnTheme from 'monaco-themes/themes/Night Owl.json'; //https://github.com/brijeshb42/monaco-ace-tokenizer -let hasLoadedDynamicEditor = false; -export const DynamicEditor = dynamic(() => import('@monaco-editor/react'), { - ssr: false, - loading: () => null -}); +import { Editor as DynamicEditor } from '@monaco-editor/react'; const useStyles = createStyles(({ token }) => ({ code: { @@ -84,7 +78,6 @@ export const AppCodeEditor = forwardRef const { cx, styles } = useStyles(); const isDarkModeContext = useBusterStylesContext((s) => s.isDarkMode); - const [isLoading, setIsLoading] = React.useState(true); const useDarkMode = isDarkMode ?? isDarkModeContext; const memoizedMonacoEditorOptions: editor.IStandaloneEditorConstructionOptions = useMemo(() => { @@ -144,9 +137,6 @@ export const AppCodeEditor = forwardRef editor.addCommand(monaco.KeyMod.CtrlCmd | monaco.KeyCode.Enter, () => { onMetaEnter?.(); }); - - setIsLoading(false); - hasLoadedDynamicEditor = true; } ); @@ -156,24 +146,18 @@ export const AppCodeEditor = forwardRef } }); - useLayoutEffect(() => { - if (hasLoadedDynamicEditor) { - setIsLoading(false); - } - }, [hasLoadedDynamicEditor]); - return (
} language={language} - className={`${className} ${isLoading ? 'pointer-events-none opacity-0' : ''}`} + className={className} defaultValue={defaultValue} value={value} theme={useDarkMode ? 'night-owl' : 'github-light'} @@ -181,18 +165,13 @@ export const AppCodeEditor = forwardRef onChange={onChangeCodeEditor} options={memoizedMonacoEditorOptions} /> - - {isLoading && ( - - - - )}
); } ); AppCodeEditor.displayName = 'AppCodeEditor'; + +const LoadingContainer = React.memo(() => { + return ; +}); +LoadingContainer.displayName = 'LoadingContainer';