uiwjs / uiwjs/react-codemirror
cursor moves to the beginning of the line while typing quickly if the CodeMirror is controlled and the render of the component containing CodeMirror takes too long
Nobody has claimed this yet.
- Dominant language
- TypeScript
- Stars
- 2.3k
- Forks
- 161
- PR merge metrics
- No merged PRs in 30d
Description
Hello! I believe I'm running into a bug. My symptoms are similar to the old https://github.com/uiwjs/react-codemirror/issues/199, but I'm using the latest version (4.23.6) and also the workaround from https://github.com/uiwjs/react-codemirror/issues/199#issuecomment-941943581 does not work for me.
So, I'm typing into my controlled <CodeMirror> and, every few keystrokes, the cursor jumps to the beginning of the text box. I believe triggering the issue is dependent on <CodeMirror> being used in a "heavy" component: if the parent of <CodeMirror> (which supplies the value) is simple, then I don't get the cursor jump. If the parent component has a bunch of other sub-components (and so the render takes longer), then I do get the bug -- so I suspect the issue is some sort of race condition whereby an update of value arrives "too late", after more key presses.
My CodeMirror invocation looks like this:
const [value, setValue] = useState("");
<CodeMirror
value={value}
onChange={(value) => setValue(value)}
/>
<MyOtherHeavyComponent/>
If I remove <MyOtherHeavyComponent/>, then it all works fine. Also, if I type slowly, it again works fine.
Contributor guide
No contributing guide indexed for this repository
First steps
- Read the whole issue, then the project's contributing guide.
- Comment on the issue to say you are picking it up — it saves two people doing the same work.
- Fork the repository and make your change on a branch.
- Open a pull request that references the issue number.
Research direction
Start by reproducing the controlled CodeMirror example from the issue with rapid typing and an additional heavy component, then compare it with the simple-parent and slow-typing cases. Review the current controlled value and onChange behavior in version 4.23.6; done means the cursor no longer jumps to the beginning during rapid typing.
Written by the indexing model from the issue text.
Assessment
- Tech stack
- react, typescript
- Domain
- frontend
- Issue type
- Bug
- Difficulty
- 4/5
- Estimated time
- 3-5 days
- Activity status
- Stale
- Clarity
- Mostly clear
- Newbie friendliness
- 35/100