sizzle icon indicating copy to clipboard operation
sizzle copied to clipboard

Throw a better error when documentElement is missing

Open mgol opened this issue 6 years ago • 1 comments

PR #439 made Sizzle crash earlier on a documentElement-missing document. However, we want selection to work on nodes inside of a <template> element for which ownerDocument will point to a document fragment with a null documentElement. As @gibson042 said in #452:

We discussed in-meeting and had rough consensus that the right behavior was to stop at a disconnected fragment but to traverse up through a fragment's <template> host when one exists. But unfortunately, it seems difficult and maybe impossible to differentiate the two. My ideal change would instead be to tolerate null documentElement, but more changes will be required for that.

mgol avatar Aug 26 '19 18:08 mgol

For the record, the same code exists in jQuery 3.x: https://github.com/jquery/jquery/blob/f79d5f1a337528940ab7029d4f8bbba72326f269/src/selector.js#L505-L512 but we're unlikely to touch it there. jQuery 4.x code already doesn't have this check: https://github.com/jquery/jquery/blob/42e50f8c21fbfd08092ad81add4ac38982ef0841/src/selector.js#L325-L332 and it doesn't result in an automatic crash as setDocument in jQuery 4.x will be much, much simpler.

mgol avatar Sep 07 '23 12:09 mgol