W3C home > Mailing lists > Public > public-webapps@w3.org > October to December 2011

Re: QSA, the problem with ":scope", and naming

From: Tab Atkins Jr. <jackalmage@gmail.com>
Date: Tue, 18 Oct 2011 16:58:20 -0700
Message-ID: <CAAWBYDB9fpaeG=2QvXBnvsGFCmy1H2X_9JgEf90KFhGDHgBtUA@mail.gmail.com>
To: Sean Hogan <shogun70@westnet.com.au>
Cc: Yehuda Katz <wycats@gmail.com>, Alex Russell <slightlyoff@google.com>, Webapps WG <public-webapps@w3.org>, John Resig <jeresig@gmail.com>, Paul Irish <paulirish@google.com>, Lachlan Hunt <lachlan.hunt@lachy.id.au>
On Tue, Oct 18, 2011 at 4:46 PM, Sean Hogan <shogun70@westnet.com.au> wrote:
> On 19/10/11 7:20 AM, Yehuda Katz wrote:
>> I agree entirely.
>> I have asked a number of practitioner friends about this scenario:
>> <div id="parent">
>> <p id="child"><span id="inline">Content</span></p>
>> </div>
>>  document.getElementById("child").querySelectorAll("div span"); // returns
>> #inline
>> In 100% of cases, people consider this behavior *broken*. Not just
>> "interesting, I wouldn't have expected that", but "who came up with that!?".
>> In all cases involving JavaScript practitioners, people expect
>> querySelectorAll to operate on the element as though the element was the
>> root of a new document, and where combinators are relative to the element.
> It matches the definition of CSS selectors, so I don't think it can be
> called broken. For this case, node.querySelectorAll("div span") finds all
> span's (in document order) which are contained within the invoking node and
> checks that they match the selector expression, in this case simply checking
> they are a descendant of a div.
> The new definition being promoted is:
> - start at the containing node
> - find all descendant div's
> - for every div, find all descendant span's.
> - with the list of span's, remove duplicates and place in document-order
> Once you understand the proper definition it is hard to see this new
> definition as more logical.
> To me, the problem here is some (not all) Javascript practitioners not
> learning the proper definition of CSS selectors.

Not at all.  I'm not sure why you think this is somehow an "improper"
way to think about things.

There are two ways you can "scope" a selector.  The first is to filter
the results of a selector match to only those under a certain element
(what QSA does today).  The second is to scope the entire selector to
only apply underneath the scoping element, which is what Alex is

An alternative view of this is that current QSA restricts the final
compound selector in a selector to match only elements in the scope,
while allowing the rest of the selector to match elements anywhere in
the document.  Alex's proposal (and every other JS selector engine)
restricts all of the selector component to matching only elements in
the scope.

There is nothing unnatural or improper about this.  The fact that
every JS selector engine works in the latter fashion, and that JS devs
are regularly surprised by the former behavior, suggests strongly that
the latter behavior is the better default behavior.

Based on discussion on the mailing list, <style scoped> will be
changing to the latter behavior as well, with the ability to invoke
the former behavior in the rare circumstances when you explicitly want

Received on Tuesday, 18 October 2011 23:59:08 UTC

This archive was generated by hypermail 2.3.1 : Friday, 27 October 2017 07:26:36 UTC