Alright, after few hours of investigating, I could not find a solution but came to a few conclusion:
- without any changes, it crashes* every single time with my Firefox (or with such a high probability that I never encountered the case when it works).
- the textarea is initialized twice. Once on "load", once on "onShow", that adds a few editors to the tinyMCE.editors array. Fixing that seems to lower the probability of failure (but I couldn't find a clean way to do this, ie: one that will work for everyone).
- removing the tinyMCE editors on "submit" GREATLY improve the probability of success. But not always, it still crashes randomly. I used a code similar from the one in "switchForm", and
tinyMCE.execCommand('mceRemoveControl', false, ed.id);
- Adding a setTimeout to initialize the editor seems to help a bit.
- Adding a setTimeout to make sure the editor has been cleared before hiding the window seems to help as well.
At the end, it still randomly crashes, and I failed at finding why.
For the record, I use Firefox 16.0.2, packaged for Ubuntu. A colleague uses Firefox 17.0.1 for Windows and has a higher success rate, but it eventually fail after a few attempts. Somehow, I wonder if time is not litteraly of the essence: he's computer is a slow piece of hardware, the manager takes few seconds to render, maybe leaving enough time for tinyMCE to properly initialize/cleanup.
And it works great with Chrome, but unfortunately the rest of the manager is often randomly broken (due to aggressive caching from Chrome), so it's not really a great help.
* By crashing, I mean that at some point, tinyMCE throws the following error:
NS_ERROR_UNEXPECTED: Component returned failure code: 0x8000ffff (NS_ERROR_UNEXPECTED) [nsIDOMHTMLDocument.implementation]