Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

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

Open
atifaziz opened this issue Aug 23, 2015 · 4 comments
Open

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

atifaziz opened this issue Aug 23, 2015 · 4 comments

Comments

@atifaziz
Copy link
Owner

atifaziz commented Aug 23, 2015

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.


Originally reported on Google Code with ID 43

Reported by HighTechRider on 2011-01-16 20:48:12

@atifaziz atifaziz self-assigned this Aug 23, 2015
@atifaziz
Copy link
Owner Author

atifaziz commented Aug 23, 2015

Is this behavior defined by CSS standard, or is it just a jQuery feature?


Reported by edin.dazdarevic on 2011-01-24 21:29:12

@atifaziz
Copy link
Owner Author

atifaziz commented Aug 23, 2015

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.


Reported by HighTechRider on 2011-01-24 22:42:17

@atifaziz
Copy link
Owner Author

atifaziz commented Aug 23, 2015

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 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.


Reported by @atifaziz on 2011-01-25 01:12:22

@atifaziz
Copy link
Owner Author

Reported by azizatif on 2011-01-25 01:12:33

  • Status changed: Accepted

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

1 participant