NOT_FOUND_ERROR when using the text() method.

NOT_FOUND_ERROR when using the text() method.

I'm seeing something truly bizarre, after upgrading to jQuery 1.5.1

SO thread here:

Basically, at certain points of my app, I am getting a 
NOT_FOUND_ERR: DOM Exception 8:
  An attempt was made to reference a Node in a context where it does not exist.
When I do something as simple as:
  1. $('.price').text('123');

I've traced it to the append() method.

  1. append: function() {
  2.     return this.domManip(arguments, true, function( elem ) {
  3.         if ( this.nodeType === 1 ) {
  4.             // this line explodes
  5.             this.appendChild( elem );
  6.         }
  7.     });
  8. },
When I "console.dir(elem)" I get a "Object".  And if I trace that back, I see domManip() cloning a "fragment", which is of type "DocumentFragment".

So I checked out domManip() who's relevant part looks like this:

  1. if ( first ) {
  2. table = table && jQuery.nodeName( first, "tr" );

  3. for ( var i = 0, l = this.length, lastIndex = l - 1; i < l; i++ ) {
  4. callback.call(
  5. table ?
  6. root(this[i], first) :
  7. this[i],
  8. results.cacheable || (l > 1 && i < lastIndex) ?
  9. jQuery.clone( fragment, true, true ) :
  10. fragment
  11. );
  12. }
  13. }

Now with a breakpoint in domManip() right before the callback() I tried the following:
  1. this[i].appendChild(jQuery.clone( fragment, true, true ))
Which crashed with the above error.  Then I tried:
  1. this[i].appendChild(fragment.cloneNode(true))
Which worked as intended.  However "table" was set to true, and my page lacks any table whatsoever, which I found odd.

My current theory is that under some sort of circumstance I can't figure out $.clone() is not cloning an object properly, and causing the browser to raise an exception because jQuery tries to append a non-node object to a node.

Could it be how the HTML is added to the DOM?  This is part of a very AJAX heavy app/framework with JS controlling HTML being written to the DOM in a lot of different ways.

If anyone has a clue why this is exploding based on some knowledge of jQuery internal that I lack, I sure would be grateful.  Because this is pretty frickin' weird.