Bug #3152

firefox component failure with reinstanciated TinyMCE

Submitted:
2010-10-04 15:49:27 By: Anonymous
Closed Priority: 3 Resolution: Works For Me Assigned to: None
User agent: Mozilla/5.0 (X11; U; Linux x86_64; fr; rv:1.9.2.10) Gecko/20100915 Ubuntu/10.04 (lucid) Firefox/3.6.10
Screen info: 1080x1920x24

Description of problem:

The following error appears in Firebug when a TinyMCE form is instanciated by a AJAX call on a field that as already been TinyMCEiffied and cleaned.

Steps to reproduce:
1. Create a AJAX form with a TinyMCE instance on a field with id "my-name"
2. Make sure the submit button for your ajax form looks like :
<input type="submit" name="save" onsubmit="if(typeof(tinyMCE) !== 'undefined') { tinyMCE.triggerSave(); unloadTinyMCE(); };" />

with the following unloadTinyMCE() function.

function unloadTinyMCE()
{
if(typeof(tinyMCE) !== 'undefined')
{
tinymce.each(tinyMCE.editors, function(e) {
if(typeof(e) !== 'undefined')
{
tinymce.remove(e);
}
});
}
}


3. save your form and remove the form content from your html page. This should work without problem
4. Load your form using ajax, and init the TinyMCE editor on the field "my-name" . This should work too.
5. Save your form : the following error appears in firebug :

Component returned failure code: 0x8000ffff (NS_ERROR_UNEXPECTED) [nsIDOMHTMLDocument.implementation]" nsresult: "0x8000ffff (NS_ERROR_UNEXPECTED)


See : http://tinymce.moxiecode.com/punbb/viewtopic.php?pid=67348
See : http://tinymce.moxiecode.com/punbb/viewtopic.php?pid=22977

This bug may have a few duplicate, but i'm creating a new bug since i've a fix for the component failure :

Replace this : from line 6328 to line 6351 :

// Nodes needs to be attached to something in WebKit/Opera
// Older builds of Opera crashes if you attach the node to an document created dynamically
// and since we can't feature detect a crash we need to sniff the acutal build number
// This fix will make DOM ranges and make Sizzle happy!
impl = n.ownerDocument.implementation;
if (impl.createHTMLDocument && (tinymce.isOpera && opera.buildNumber() >= 1767)) {
// Create an empty HTML document
doc = impl.createHTMLDocument("");

// Add the element or it's children if it's a body element to the new document
each(n.nodeName == 'BODY' ? n.childNodes : [n], function(node) {
doc.body.appendChild(doc.importNode(node, true));
});

// Grab first child or body element for serialization
if (n.nodeName != 'BODY')
n = doc.body.firstChild;
else
n = doc.body;

// set the new document in DOMUtils so createElement etc works
oldDoc = t.dom.doc;
t.dom.doc = doc;
}


By :

if(tinymce.isOpera && opera.buildNumber() >= 1767) {
impl = n.ownerDocument.implementation;
if (impl.createHTMLDocument) {
// Create an empty HTML document
doc = impl.createHTMLDocument("");

// Add the element or it's children if it's a body element to the new document
each(n.nodeName == 'BODY' ? n.childNodes : [n], function(node) {
doc.body.appendChild(doc.importNode(node, true));
});

// Grab first child or body element for serialization
if (n.nodeName != 'BODY')
n = doc.body.firstChild;
else
n = doc.body;

// set the new document in DOMUtils so createElement etc works
oldDoc = t.dom.doc;
t.dom.doc = doc;
}
}


The change is minor :

it puts "impl = n.ownerDocument.implementation;" that cause the firefox components failure in the "if(tinymce.isOpera && opera.buildNumber() >= 1767) {" test.
This fix the component failure in firefox.

Reported by: Pierre-Yves Landur?Id: 3080912

 

If you wish to follow or post a comment, you need to be registered and logged in.

Comments

User Image
  • 2012-10-25 15:22:18

as

Hello!

I can confirm that your solution works. Tested on Windows Firefox 16.0.1 with tinyMCE 3.5.6 inside jquery.colorbox.

Hope your bug fix will make it into an official version!

User Image
  • 2013-02-14 15:14:31

toddtomlinson

Is there any movement on getting this into core. I ran into this problem on a Drupal site using the WYSIWYG module and TinyMCE. The issue is identical to the original description in this ticket. A modal window driven by ajax with TinyMCE textarea - clicking Save threw an error:

NS_ERROR_UNEXPECTED: Component returned failure code: 0x8000ffff (NS_ERROR_UNEXPECTED) [nsIDOMHTMLDocument.implementation]
[Break On This Error]

...,function(){l[s]=i;g--;n(s);o()})}});if(!g){a.each(d,function(s){s.func.call(s.s...

Implementing the fix listed in the original posting fixed the problem.

User Image
  • 2013-02-14 16:04:09

Elijah Lynn

Thanks Todd!

I am not sure of the TinyMCE process but... Do we need to submit an official patch for this to make it in? Does anyone know?

User Image
  • 2013-03-04 14:39:22

Elijah Lynn

Here is a pull request that fixes this issue. This won't really help anyone unless they can recompile TinyMCE though - https://github.com/tinymce/tinymce/pull/175

User Image
  • 2013-03-04 16:06:40

Elijah Lynn

The actual fix that Todd implemented above is this diff on 3.5.6 of the tiny_mce_src.js, then it was minified using http://javascriptcompressor.com/ and then the output of that replaces the contents of tiny_mce.js.

Since I cannot upload files here I am going to upload it to the issue on Drupal.org. http://drupal.org/node/1907756#comment-7133690

User Image
  • 2013-07-24 22:02:23

Luke_sf

This is still happening in Firefox 22, Tinymce 3.5.8.

User Image
  • 2014-05-28 22:52:00

solaris

This is still happening in Firefox 29, Tinymce 4.0.

User Image
  • 2014-06-25 09:37:02

commilfo

This is still happening in Firefox 30, Tinymce 4.1.

User Image
  • 2014-09-04 11:57:41

spocke

The error will only appear if you have editor instances removed from DOM without using the methods provided by TinyMCE.

The code from the original bug report if faulty since it's removing editor instances while iterating the same collection this means it will skip over editors since the index will be wrong.

Use the tinymce.remove(); method to re-init editor instances.

I've produced a fiddle here where I explain how to use the tinymce.remove call and it doesn't produce any errors on Firefox when re-initializing the editors though a fake Ajax call. If there is a bug then please provide a Fiddle that reproduces it thanks.

Here is the working example of Ajax updates with TinyMCE: http://fiddle.tinymce.com/Bveaab

User Image
  • 2014-09-15 13:52:21

hercules

Hi,
I have repeated the code spocke suggested above in a real ajax environment and i was still getting the same error.

However to fix this, strangely all i had to do was wrap the removal line in a try catch block:

try {
tinymce.remove();
} catch (e) {}

It's almost like its surpressing the firefox bug but still removing the instances. So far i've not encountered any problems. I hope this can help others.

User Image
  • 2014-09-22 21:58:16

solaris

Wow. Yes, the fix hercules posted did fix the issue for us. Thank you!
The issue was occurring not only in Firefox but also in IE (tested on IE11).
We were using jquery's ui-dialog to populate the editor which could be called multiple times replacing the content using tinyMCE.activeEditor.setContent().
But it would work only for the first call. As spcocke said in his previous comment here:

>The error will only appear if you have editor instances removed from DOM without using the methods provided by TinyMCE.

I think this was the cause of the issue: a dialog is closed 'removing the editor from DOM' but not using tynymce's remove() method.

Adding just `tinymce.remove();` didn't fix it, but wrapping it in a try-catch block did.

Thanks spocke and hercules!

User Image
  • 2014-09-22 22:34:38

hercules

No problemo! I was hoping my fix could help someone.

User Image
  • 2014-09-22 23:28:51

solaris

There must be an error happening inside the remove(), that is why try-catch block makes it work. I d like to create a test case for spocke to demonstrate it.