Closed gyopiazza closed 4 months ago
You need to call initialize
from @codingame/monaco-editor-wrapper
The documentation needs to be updated indeed
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.
I hope you understand it will be difficult to help you with so little information
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.
Can you please provide a small reproduction working project?
Here is a bare minimum example, you should notice some heavy flickering in the minimap/scrollbar: https://codesandbox.io/p/devbox/lrv44q
Here's how to fix all the issues:
scrollBeyondLastLine
monaco feature. So either use a fixed size or disable that feature@codingame/esbuild-import-meta-url-plugin
plugin to the optimizeDeps.esbuildOptions.plugins in your vite config.mts
or adding "type": "module"
to the package.jsoninitialize
function should only be called once, and the react Strict mode make the effects to be called twice. So instead call it outside of the component once and wait for the returned promise in the componentHere's the fixed version: https://codesandbox.io/p/devbox/monaco-editor-react-forked-6v49r7
Thank you very much!
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
I have the following dependencies and the package manager is
yarn
Thank you in advance for the support :)