tinymce / tinymce-react

Offical TinyMCE React component
MIT License
937 stars 152 forks source link

onEditorChange is fired three times if text was selected and is overwritten by paste #470

Closed m4r71n closed 6 months ago

m4r71n commented 10 months ago

What is the current behavior?

onEditorChange is fired three times if text was selected and is overwritten by paste. Also the content is wrong. Reproducible on https://tinymce.github.io/tinymce-react/iframe.html?id=editor--controlled-input&viewMode=story with Firefox 117, Edge and Chrome 116.

Select some text and paste other text with ctrl+v. Please see attached video: onEditorChange.webm The logpoint in the video is on:

onEditorChange: function onEditorChange(e) {
    return setData(e)
}

What is the expected behavior?

The correct content with the pasted text.

TinyITAdmin commented 10 months ago

Ref: INT-3226

danoaky-tiny commented 7 months ago

I've been able to replicate your case with 2 identical logs after pasting over some content, see here: https://codesandbox.io/p/sandbox/runtime-water-gff5js

This is because onEditorChange is called for several different TinyMCE events, so it's possible for some events to fire at the same time.

As a workaround, you could try and debounce calls made to your onEditorChange callback.

Let us know if that helps.

github-actions[bot] commented 6 months ago

This issue is stale because it has been open for 30 days with no activity. Respond with a comment or this will be closed in 7 days.