uiwjs / react-codemirror

CodeMirror 6 component for React. @codemirror https://uiwjs.github.io/react-codemirror/
https://uiwjs.github.io/react-codemirror/
MIT License
1.69k stars 135 forks source link

CodeMirrorMerge gets unfocused on value change #566

Open denbalogh opened 1 year ago

denbalogh commented 1 year ago

When I use CodeMirrorMerge with onChange prop in the CodeMirrorMerge.Original component, the editor gets unfocused every time I change the value.

It is happening since the 4.21.2 update.

denbalogh commented 1 year ago

Here's the issue in codesandbox https://codesandbox.io/s/bold-estrela-rzqwck?file=/src/App.js

denbalogh commented 1 year ago

@jaywcjlove I updated to latest release and now it won't even render the editor. Codesandbox

jaywcjlove commented 1 year ago

https://github.com/uiwjs/react-codemirror/blob/92c4abef63a5cbe4737fb5bea8ca6ea869e9a8c0/merge/src/index.tsx#L11-L14

@denbalogh I'm trying to fix it by adding a destroyRerender prop to turn off re-rendering the component on every update.

https://github.com/uiwjs/react-codemirror/blob/92c4abef63a5cbe4737fb5bea8ca6ea869e9a8c0/merge/src/Internal.tsx#L78-L84

During the update, all extensions will be lost. If you add dispatch({ effects }), an @codemirror/merge internal error will be triggered.

So I thought of a compromise method and regenerated it after updating, which caused the onChange problem.

https://github.com/uiwjs/react-codemirror/blob/92c4abef63a5cbe4737fb5bea8ca6ea869e9a8c0/merge/src/Internal.tsx#L99-L119

denbalogh commented 1 year ago

@jaywcjlove Is that a difficult problem to solve, will it take long? Sorry to be a bother, but we count on this functionality in our project.

jaywcjlove commented 1 year ago

https://codesandbox.io/embed/https-github-com-uiwjs-react-codemirror-issues-566-sff6t3?fontsize=14&hidenavigation=1&theme=dark

@denbalogh Looks like the problem is solved

denbalogh commented 1 year ago

@jaywcjlove yes, seems like it is. Thank you, very appreciated 🙏