-
Notifications
You must be signed in to change notification settings - Fork 20.6k
Description
When attempting to upgrade from jQuery 3.6.1 to 3.7.0 in MediaWiki, the Wikipedia ecosystem integration tests failed (https://gerrit.wikimedia.org/r/c/mediawiki/core/+/923762). Credit to @santhoshtr for finding the root cause and the minimum test case.
var doc = new DOMParser().parseFromString( '<span>text</span>', 'text/html' );
$(doc).text();
// Expected: "text"
// Actual: "null"
Link to test case
https://codepen.io/Krinkle/pen/eYPqYWm
var doc = new DOMParser().parseFromString( '<span>text</span>', 'text/html' )
document.write("Version: "+$jqv361.fn.jquery);
document.write(". " + $jqv361(doc).text())
document.write("<br>Version: "+$jqv370.fn.jquery);
document.write(". " + $jqv370(doc).text())
Version: 3.6.4. text
Version: 3.7.0. null
Other details
By placing a debugger statement in the test case and walking through, the difference is seen in the code.
In jQuery 3.6.x, we have Sizzle.getText
with a combined conditional for several node types (1, 9, 11), where nodeType === 9
is for a Document object. The conditional block includes a fallback for textContent
, because Document objects don't have a textContent
property (only the inner <html>
document element does).


In jQuery 3.7.0, the equivalent jQuery.text
function has the same conditional block but now unconditionally returns elem.textContent
.
