CodinGame / monaco-editor-react

16 stars 2 forks source link

Monaco not initialized #47

Closed gyopiazza closed 4 months ago

gyopiazza commented 4 months ago

Hello! I've just installed it in a NextJS app but the basic example fails with the following error, which can be pin-pointed to MonacoEditor.tsx#L161

image

I have the following dependencies and the package manager is yarn

"@codingame/monaco-editor-react": "^5.2.2",
"@codingame/monaco-editor-wrapper": "^5.3.2",
"monaco-editor": "npm:@codingame/monaco-vscode-editor-api",
"vscode": "npm:@codingame/monaco-vscode-api",

Thank you in advance for the support :)

CGNonofr commented 4 months ago

You need to call initialize from @codingame/monaco-editor-wrapper

The documentation needs to be updated indeed

gyopiazza commented 4 months ago

Thanks @CGNonofr! I've added the initialize and set a isReady state after the promise is resolved, but then the editor renders with some weird flickering and it doesn't seem very responsive.

CGNonofr commented 4 months ago

I hope you understand it will be difficult to help you with so little information

gyopiazza commented 4 months ago

This is how I'm mounting the editor:

import Editor from '@codingame/monaco-editor-react';
import { initialize } from '@codingame/monaco-editor-wrapper';
import { useEffect, useState } from 'react';

export default function VSCode() {
  const [isReady, setIsReady] = useState(false);
  const [value, setValue] = useState('// some comment');

  useEffect(() => {
    initialize().then(() => setIsReady(true));
  }, []);

  return isReady && <Editor height='auto' programmingLanguage='javascript' value={value} onChange={setValue} />;
}

In this video (60fps) you'll notice that it slowly renders the editor, line by line, the typing is not fluid and after a while the minimap crashes. https://github.com/CodinGame/monaco-editor-react/assets/748898/dda5fd8c-cf96-4802-93b8-aa44a5c22b54

I could be doing something wrong, but it feels like it's loading more than one instance or doing some extra processing.

CGNonofr commented 4 months ago

Can you please provide a small reproduction working project?

gyopiazza commented 4 months ago

Here is a bare minimum example, you should notice some heavy flickering in the minimap/scrollbar: https://codesandbox.io/p/devbox/lrv44q

CGNonofr commented 4 months ago

Here's how to fix all the issues:

Here's the fixed version: https://codesandbox.io/p/devbox/monaco-editor-react-forked-6v49r7

gyopiazza commented 4 months ago

Thank you very much!