amoikevin / fizzler

Automatically exported from code.google.com/p/fizzler
GNU General Public License v3.0
0 stars 0 forks source link

Multiple-selector doesn't return elements in document order #43

Open GoogleCodeExporter opened 9 years ago

GoogleCodeExporter commented 9 years ago
http://api.jquery.com/multiple-selector/ states that for a multiple-selector 
"The order of the DOM elements in the returned jQuery object ... will be in 
document order."

Fizzler doesn't respect this order, instead returning all the matches for each 
selector in turn and not in document order.

Original issue reported on code.google.com by HighTech...@gmail.com on 16 Jan 2011 at 8:48

GoogleCodeExporter commented 9 years ago
Is this behavior defined by CSS standard, or is it just a jQuery feature? 

Original comment by edin.daz...@gmail.com on 24 Jan 2011 at 9:29

GoogleCodeExporter commented 9 years ago
Whilst jQuery does define this, the CSS spec does not appear to: CSS3 "A 
comma-separated list of selectors represents the union of all elements selected 
by each of the individual selectors in the list."

Since jQuery and Fizzler can be used to manipulate (and not just display) 
documents it's arguably far more important that they each define an order for 
how that union happens.

Original comment by HighTech...@gmail.com on 24 Jan 2011 at 10:42

GoogleCodeExporter commented 9 years ago
Fizzler intentionally does not return the results in document order because 
running a sort would end up buffering the results prior to yielding them. This 
was done to maintain deferred execution semantics as much as possible and make 
the caller pay for only the least necessary computation. For cases where 
document order is significant, it seemed reasonable to let the caller compose 
the results of QuerySelectorAll with OrderBy.

HtmlAgilityPack.HtmlNode has a StreamPosition property that can be used as the 
key to get the results sorted in document order. Unfortunately, earlier 
versions of HtmlAgilityPack also seemed to have an unreliable StreamPosition so 
that was another (though lesser) reason for delegating the decision to sort to 
the caller.

I am less concerned with jQuery. What Fizzler clearly violates is the 
querySelectorAll contract specified as part of the NodeSelector[1] interface 
and which states:

> The querySelectorAll() method on the NodeSelector interface 
> must, when invoked, return a NodeList containing all of the 
> matching Element nodes within the node’s subtrees, in 
> document order.

One way forward I see is first have QuerySelectorAll return nodes in document 
order. This way, there are no surprises but it will be clearly returning 
buffered results (the inefficiency of which may in itself surprise others). 
Then supply a non-normative alternative (YieldQuerySelectorAll?) that does not 
guarantee document order but which streams out the results.

[1] http://www.w3.org/TR/selectors-api/#nodeselector

Original comment by azizatif on 25 Jan 2011 at 1:12

GoogleCodeExporter commented 9 years ago

Original comment by azizatif on 25 Jan 2011 at 1:12

GoogleCodeExporter commented 9 years ago
This issue has been migrated to:
https://github.com/atifaziz/Fizzler/issues/43
The conversation continues there.
DO NOT post any further comments to the issue tracker on Google Code as it is 
shutting down.
You can also just subscribe to the issue on GitHub to receive notifications of 
any further development.

Original comment by azizatif on 23 Aug 2015 at 1:34