Search code examples
javascriptreactjstinymcewhitespacetinymce-6

First whitespace doesn't trigger the onEditorChange function in react JS TinyMCE version 6.8.2


I've asked the same question on tinymce github too and seems like no one cares. Does anyone have any idea why the first whitespace we enter to the editor is not recognized by the tinymce editor? I'm self hosting tinymce 6.8.2 in my react project. When I try to console the html text of the editor, it doesn't show the first whitespace. But when I add two whitespaces it shows two &nbsp's, It works well with every other characters, but it doesn't work with first whitespace. I'll provide the code sandbox link where I tested if this issue is common or not, I've consoled the html in it, Can anyone help? Thank you in advance. Code Sandbox : https://codesandbox.io/p/sandbox/tinymce-react-demo-forked-t38l25?file=%2Fsrc%2FDocumentEditor.jsx


Solution

  • This is not the best solution but I did find a workaraound for this. It's still not the perfect solution as it does have some bugs. Anyways this worked for me. If anyone bump into the same issue and have no idea what to do, they can at least try this.

    onDirty={(element, editor) => { /* Write your code here. */ }}

    Use this inside the Editor component and it'll be triggered when we enter the first whitespace (Or whatever we enter). Again, this is just something that worked for me and I'm not sure if this helps someone else. It's still worth a try.