Copilot commented on code in PR #3169: URL: https://github.com/apache/apisix-dashboard/pull/3169#discussion_r2272012891
########## src/components/form/Editor.tsx: ########## @@ -106,8 +106,8 @@ export const FormItemEditor = <T extends FieldValues>( const [internalLoading, setLoading] = useState(false); useEffect(() => { - if (!monaco) return; setLoading(true); + if (!monaco) return; Review Comment: The check for `monaco` happens after `setLoading(true)` is called, which means loading state will be set to true even when monaco is not available. This could leave the component in a perpetual loading state. ```suggestion if (!monaco) { setLoading(false); return; } setLoading(true); ``` ########## src/components/form/Editor.tsx: ########## @@ -31,12 +31,9 @@ import { useTranslation } from 'react-i18next'; import { genControllerProps } from './util'; -type SetupMonacoProps = { - monaco: Monaco; -}; - -const setupMonaco = ({ monaco }: SetupMonacoProps) => { - window.MonacoEnvironment = { +// #region Monaco Editor Setup +const initializeMonacoEditor = () => { + self.MonacoEnvironment = { Review Comment: Using `self` instead of `window` may cause issues in environments where `self` is not defined (e.g., Node.js environments during SSR). Consider using `globalThis` or checking for the existence of `self` before assignment. ```suggestion globalThis.MonacoEnvironment = { ``` ########## src/components/form/Editor.tsx: ########## @@ -45,10 +42,13 @@ const setupMonaco = ({ monaco }: SetupMonacoProps) => { }, }; loader.config({ monaco }); - return loader.init(); + loader.init(); }; -const options: editor.IStandaloneEditorConstructionOptions = { +initializeMonacoEditor(); Review Comment: Calling `initializeMonacoEditor()` at module level may cause issues during server-side rendering or testing environments where the Monaco editor workers are not available. Consider moving this initialization to a useEffect or component mount lifecycle. ```suggestion ``` -- This is an automated message from the Apache Git Service. To respond to the message, please log on to GitHub and use the URL above to go to the specific comment. To unsubscribe, e-mail: notifications-unsubscr...@apisix.apache.org For queries about this service, please contact Infrastructure at: us...@infra.apache.org