Bug Tracker

Ticket #9479 (closed bug: worksforme)

Opened 3 years ago

Last modified 3 years ago

o is null

Reported by: anonymous Owned by: anonymous
Priority: low Milestone: 1.next
Component: effects Version: 1.6.1
Keywords: Cc:
Blocking: Blocked by:

Description

in firefox I obtain always "o is null" when using toggle()

Change History

comment:1 Changed 3 years ago by addyosmani

  • Owner set to anonymous
  • Priority changed from undecided to low
  • Status changed from new to pending
  • Component changed from unfiled to effects

Thanks for taking the time to contribute to the jQuery project! Please provide a reduced jsFiddle test case to help us assess your ticket!

Additionally, be sure to test against the jQuery Edge version to ensure the issue still exists. To get you started, use this boilerplate:  http://jsfiddle.net/rwaldron/da3nM/ Open the link and click to "Fork" in the top menu.

comment:2 Changed 3 years ago by anonymous

  • Status changed from pending to new

Hello, I found that this error "o is null" appears just with 1.6.1 while if I use 1.5.1 I obtain a "JQuery is not defined" on the jquery UI code which is loaded correctly after JQuery.

I am using Firefox 4.0.1

My page is XHTML 1.0 Transitional (validated) and I am pretty sure that I had no problems using HTML 4.0 with JQuery.

Now I upgraded to XHTML 1.0 and JQuery doesn't work anymore even if I downgrade to older versions.

My code is almost stupid as first rows are just calling a toggle() function on a div.

So the same page with different jquery versions provides different errors.

I can't help more at the moment.

Best regards

Roberto

comment:3 Changed 3 years ago by addyosmani

  • Status changed from new to closed
  • Resolution set to worksforme

Using the information you've provided, I've put together a test case using XHTML 1.0 transitional, jQuery edge (1.6.1-post, our current in-development version) and a basic toggle() example here  http://jsfiddle.net/BLQRu/2/. Running this in Firefox 4.01, Chrome and the latest version of the other popular browsers, everything appears to work fine without error messages being output.

With this in mind, I'm tempted to think that the problem you're experiencing may be related to your code or what you're trying to do. If you need further assistance debugging the issue, please feel free to speak to a community member about it in our forums or on IRC/freenode under the #jquery channel. Should this result in some more information on the cause of the issue, we'll be happy to re-evaluate.

comment:4 Changed 3 years ago by anonymous

Thanks for your evaluation, but it seems this is a racing condition or however a kind of assumption in jquery code that doesn't work with my page.

I found using the debugger that jquery 1.6.1 fails inside its "clean" function I reported below.

MY EVALUATION:

Inside the clean function JQuery does a:

div = context.createElement("div");

...later it executes the following which is resulting in a null "div" variable.

Move to the right depth while ( depth-- ) {

div = div.lastChild;

}

...at the end of the clean function we have a "null pointer" trying to use the null div variable:

elem = div.childNodes;

Pratically I see here two problems: 1) There is an assumption that the created div has child nodes 2) There is not a protection against the null pointer

In order to workaround this error I should understand what's wrong in my code (I mean: what jquery don't like in my valid xhtml 1.0)

I would appreciate some suggestions as I can't understand the logic of the clean function code, sorry. Thank you in advance.

JQuery's Clean function code

clean: function( elems, context, fragment, scripts ) {

var checkScriptType;

context = context
document;

!context.createElement fails in IE with an error but returns typeof 'object' if ( typeof context.createElement === "undefined" ) {

context = context.ownerDocument
context[0] && context[0].ownerDocument document;

}

var ret = [], j;

for ( var i = 0, elem; (elem = elems[i]) != null; i++ ) {

if ( typeof elem === "number" ) {

elem += "";

}

if ( !elem ) {

continue;

}

Convert html string into DOM nodes if ( typeof elem === "string" ) {

if ( !rhtml.test( elem ) ) {

elem = context.createTextNode( elem );

} else {

Fix "XHTML"-style tags in all browsers elem = elem.replace(rxhtmlTag, "<$1></$2>");

Trim whitespace, otherwise indexOf won't work as expected

var tag = (rtagName.exec( elem )
["", ""])[1].toLowerCase(),
wrap = wrapMap[ tag ]
wrapMap._default,

depth = wrap[0], div = context.createElement("div");

Go to html and back, then peel off extra wrappers div.innerHTML = wrap[1] + elem + wrap[2];

Move to the right depth while ( depth-- ) {

div = div.lastChild;

}

Remove IE's autoinserted <tbody> from table fragments if ( !jQuery.support.tbody ) {

String was a <table>, *may* have spurious <tbody> var hasBody = rtbody.test(elem),

tbody = tag === "table" && !hasBody ?

div.firstChild && div.firstChild.childNodes :

String was a bare <thead> or <tfoot> wrap[1] === "<table>" && !hasBody ?

div.childNodes : [];

for ( j = tbody.length - 1; j >= 0 ; --j ) {

if ( jQuery.nodeName( tbody[ j ], "tbody" ) && !tbody[ j ].childNodes.length ) {

tbody[ j ].parentNode.removeChild( tbody[ j ] );

}

}

}

IE completely kills leading whitespace when innerHTML is used if ( !jQuery.support.leadingWhitespace && rleadingWhitespace.test( elem ) ) {

div.insertBefore( context.createTextNode( rleadingWhitespace.exec(elem)[0] ), div.firstChild );

}

elem = div.childNodes;

}

}

comment:5 Changed 3 years ago by anonymous

SOLVED:

JQuery raises "o is null" or "div is null" during the "clean" action with an XHTML page that uses JQuery and JQuery UI with the XML processing instruction at the top. The behaviour of JQuery is correct to identify an XML processable document using the processing instruction, but XHTML is actually an XML file and it is correct to use the processing instruction or it as well. I really think JQuery should look at the doctype to verify if it is an XHTML page before reading the page as XML.

This way JQueryUI doesn't work:

<?xml version="1.0" encoding="UTF-8" ?> <!DOCTYPE html PUBLIC "-W3CDTD XHTML.............

This is ok. <!DOCTYPE html PUBLIC "-W3CDTD XHTML.............

Hope this help

Roberto

Note: See TracTickets for help on using tickets.