-
Notifications
You must be signed in to change notification settings - Fork 111
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Issue with pressing Enter when using with React #23
Comments
Thanks for reporting. I first tried in Firefox, there the issue doesn't happen. On Chrome I can reproduce your issue. |
So I found out that the issue is related to the controlling of I'd say that uncontrolled should also be the recommendation for the React demo as well; this thread facebook/react#955 shows a long running confusion with controlled inputs with regards to state in React, so considering the editor works as expected and can pass updates when uncontrolled, I think that makes most sense. |
Just to have some context, I want
Having a mix of controlled and non-controlled use cases makes things complicated indeed. I'm afraid there is no way around it except when removing some of the use-cases above. I've done a bit of debugging in the sandbox, here an adapted version with some logging that gives insight: https://codesandbox.io/s/svelte-jsoneditor-react-issue-23-yfobq?file=/src/App.js What I noticed is that when you press enter in code mode, in most of the cases this will trigger two changes: first a change with the new return character added, directly followed by a change that has added indentation to the new line. In React, the
I'm not sure why the caret is only reset on Chrome and not Firefox. Maybe Firefox has some smartness in place to keep caret positions in place or so. So how to solve this?
Any thoughts? |
I've implemented the de-bouncing solution in bc2c559 and published this in |
Thanks for all the help debugging here, this is super helpful. The debounce feels like a safe, but less than ideal solution. I agree that making it uncontrolled in react is a workaround. This seems like a much better workaround than just leaving it uncontrolled, but it is still a workaround to deal with the double call to I feel like the best possible solution here would be for a correction to the indentation inside ace editor before emitting the first |
Well, yes that would prevent this issue, but it's not really an issue in ace editor itself. It is a React specific issue, caused by the combination of the async rerendering of react and us wanting to control a controlled component from outside. In theory it can happen anyway in Ace editor when pressing two characters infinitely fast after each other, resulting in two onChange events like we see with the indentation. Anyway, I think it's fine having this debouncing in place. It does not only solve the async issue in React, but also reduces the amount of rerenders/roundtrips when triggering onChange less often. |
This is an issue in the sandbox:
When you are in Code mode and press enter it resets the cursor to the top of the editor. I am assuming this has something to do with the implementation of the value or onChange in the ace editor, but would appreciate help with debugging this.
The text was updated successfully, but these errors were encountered: