Skip to content
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

onChange called when the readOnly option gets changed with a value update #504

Open
christiangrothaus opened this issue Jul 6, 2023 · 4 comments · May be fixed by #605
Open

onChange called when the readOnly option gets changed with a value update #504

christiangrothaus opened this issue Jul 6, 2023 · 4 comments · May be fixed by #605

Comments

@christiangrothaus
Copy link

christiangrothaus commented Jul 6, 2023

Describe the bug
Updating the value of the readOnly option while also updating the value programmatically causes onChange to be called.

To Reproduce

  1. Use a state value for the readOnly option and the value prop
  2. Update both the readOnly option and the value prop
  3. The onChange function should get called

I linked a working example below.
https://codesandbox.io/s/cool-spence-ps2dwx?file=/src/App.js

Expected behavior
I would expect onChange not to be called.

Desktop (please complete the following information):

  • OS: MacOS
  • Browser: Chrome
  • Version: 114.0.5735.198
@suren-atoyan
Copy link
Owner

@christiangrothaus I don't think there is something about readOnly option. You change the value and onChange is being called. Am I missing something?

@christiangrothaus
Copy link
Author

christiangrothaus commented Oct 6, 2023

@christiangrothaus I don't think there is something about readOnly option. You change the value and onChange is being called. Am I missing something?

When updating the value of the editor programmatically and changing it to read only at the same time the onChange function is being called. I would expect that the onChange function is only called when a user input causes the change. In the CodeSandbox example if you click the button at the bottom the background should be staying red since the onChange function shouldn't be called. In my project, we got around this by preventing both of these changes happening in the same state batch. Here is an example that shows updating the two separately avoids the issue, https://codesandbox.io/s/staging-river-8m9mkj?file=/src/App.js. The only change is the addition of the flushSync.

@togo5
Copy link

togo5 commented Apr 6, 2024

@suren-atoyan I also encountered this issue. It appears that when the Editor's readOnly is set to true, updating the value triggers the onChange event. Here is the code that causes the bug.

https://codesandbox.io/p/sandbox/quirky-glitter-kvhjqm?file=%2Fsrc%2FApp.tsx

I have also created a PR (#605) for this fix. Please review it.

@nanianlisao
Copy link

@togo5 If this PR is merged, it will result in a big breakChange, which is even harder to accept

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging a pull request may close this issue.

4 participants