tinymce-react: TinyMCE in IonModal fails to start when initialised a second time
What is the current behavior? I have an Editor on an IonModal if I open the modal twice the Editor crashes and fails to render.
Please provide the steps to reproduce and if possible a minimal demo of the problem via codesandbox.io or similar. You can find a minimal example of this here: https://codesandbox.io/s/jolly-fire-d7l52?file=/src/App.js If you press “Show Modal” twice it crashes with
tinymce.min.js:2 Uncaught TypeError: Cannot read property 'open' of undefined
What is the expected behavior?
The Editor should show up.
Which versions of TinyMCE, and which browser / OS are affected by this issue? Did this work in previous versions of TinyMCE or tinymce-react?
Google Chrome | 87.0.4280.141
@tinymce/tinymce-react 3.9.0 @ionic/react 5.5.2 @ionic/react-hooks 0.0.8 @ionic/react-route 5.3.4
I figure it’s a problem with the IonModal and my current workaround to use the Material-UI Modal works. I just thought I should let someone know.
About this issue
- Original URL
- State: closed
- Created 3 years ago
- Reactions: 4
- Comments: 21 (9 by maintainers)
Thanks for the reply @Marruixu. Yes I eventually also tried using tinymce directly with a
textarea(no react wrapper) but bumped into other problems (missing themes, icons) and even though I tried importing them, the current project’s gulp setup is not ready for this approach… I put a pin on it because of the time that this adaptation might take.Still, it seems that the solution is simply not using the library, which is a pitty …
I’m suffering from the same issue. Although the editor is not inside a modal, it’s an element that either gets added or removed from the DOM. As soon as it’s added a second time, I’m faced with the “Cannot read property ‘open’ of undefined” error. @Marruixu I’ve tried sending a different
idon each mount but without any luck…PR is here: https://github.com/tinymce/tinymce-react/pull/264/files
@1dl3 I think I have a solution: https://codesandbox.io/s/tinymce-issues204-fixed-kvw6t
I will put in a PR.
Hi, I share a workaround that I have quickly come up with, which I hope it may help or inspire for those using something like Ionic 5 Modal with React:
Essentially consists in changing the attribute
idevery time, for example, by increasing a counterimport tinymce from 'tinymce/tinymce';<script src="%PUBLIC_URL%/tinymce/tinymce.js"></script>and place the unminfied (or minfied, then change URL accordingly) resources at /public/tinymce<textarea id={"myTinyMCE" + initCounter} defaultValue={content} />inside IonModalconst [initCounter, setInitCounter] = useState<number>(0);andconst [content, setContent] = useState<string>();(assuming Typescript here)tinymce.get("myTinyMCE" + initCounter).getContent();and usesetContent()for exampleSure this can be improved, but as a start point I hope it helps other people solving this problem without having to look out for another editor until the wrapper works for this situations.
Well my best guess is that something to do with shadow-dom is interacting badly with TinyMCE because it seems to be having trouble getting things that are normally available globally on the window like document and styleSheets.
I tried it with the latest editor unminfied here: https://codesandbox.io/s/wizardly-cherry-pl159?file=/src/App.js
Honestly I have no idea how to fix this.