uiwjs / react-codemirror

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

CodeMirror Merge example has a bug #530

Closed BunnyGeorgianIvan closed 1 year ago

BunnyGeorgianIvan commented 1 year ago

There seems to be a bug in the example. Whenever a change/render occurs, the editor loses focus and is reset/reinitialized. with the original value.

https://uiwjs.github.io/react-codemirror/#/merge/onchange https://codesandbox.io/s/wonderful-kate-xr2sd9?file=/src/App.js:303-316

jaywcjlove commented 1 year ago

https://github.com/uiwjs/react-codemirror/blob/528759f6f0b47bd0bebdb7c49bfbec63dbd56264/merge/src/Internal.tsx#L98-L116

@BunnyGeorgianIvan This is because I cannot compare whether the extensions have changed, and I am still at a loss.

https://github.com/uiwjs/react-codemirror/blob/528759f6f0b47bd0bebdb7c49bfbec63dbd56264/merge/src/Internal.tsx#L89-L95

jaywcjlove commented 1 year ago
image

@BunnyGeorgianIvan If I use dispatch to update extension it will throw an error. So I used a special method to solve this problem, but it caused a new problem, that is, the editor will be re-rendered.

I think this problem may need to be solved officially by @codemirror/merge

https://github.com/uiwjs/react-codemirror/blob/528759f6f0b47bd0bebdb7c49bfbec63dbd56264/merge/src/Internal.tsx#L89-L95

https://github.com/uiwjs/react-codemirror/blob/528759f6f0b47bd0bebdb7c49bfbec63dbd56264/merge/src/Internal.tsx#L77-L82

BunnyGeorgianIvan commented 1 year ago

@jaywcjlove Got it. Thank you for the quick response and the clarification! 🙇