[csswg-drafts] [selectors] Weaken the "default namespace" rule? (#9810)

tabatkins has just created a new issue for https://github.com/w3c/csswg-drafts:

== [selectors] Weaken the "default namespace" rule? ==
From @Loirooriol in <https://github.com/w3c/csswg-drafts/issues/5684#issuecomment-1894699872>:

> I think it can be confusing that the meaning changes depending on the context. Wouldn't it have been better to just drop
> 
> > If a [default namespace](https://drafts.csswg.org/css-namespaces-3/#default-namespace) is declared, [compound selectors](https://drafts.csswg.org/selectors/#compound) without [type selectors](https://drafts.csswg.org/selectors/#type-selector) in them still only match elements in that default namespace.
> 
> Authors could use an explicit * to restrict to the default namespace if they wanted.
> 
> Possibly not web-compatible to change now, but I think default namespaces aren't actually used that much...

This is an alternate proposal that we resolved to split out into a separate issue for discussion; if we adopted this, we could ignore #9804 and #9806.

Basically, right now, if you wrote `@namespace "https://the.svg.namespace";`, then write a selector like `.foo`, it will only match *SVG* elements with the `foo` class. In a mixed HTML/SVG document, it won't match an HTML element; you have to explicitly write `html|*.foo` (and declare the `html` namespace, of course), or `*|*.foo` if you just want everything.

Oriol's suggestion is that we only apply the default namespace to *type* selectors; effectively, the rule just becomes "whenever you write a type selector (or universal selector) without a namespace, it gains the default namespace". So, writing `a` would only match `<svg:a>` elements, while `.foo` would match any element with `foo` class, regardless of namespace.

This largely obviates the current `:is()`/etc exception; writing `html|div:is(.foo, .bar)` would work the intuitive way, since the `.foo` and `.bar` would match any namespace. Similarly, changing `a.foo` into `.foo:is(a, div)` would continue to work intuitively, only matching `<svg:a>` elements (and trying to match `<svg:div>` elements, which don't exist), which ends up being the same as current behavior via a different route. (Currently, the `.foo` only matches SVG namespace elements, and `a` and `div` match any namespace, so you end up still only matching `<svg:a>` and `<svg:div>`.)

However, this is a change in behavior. It means that a selector like `[foo]` in a mixed-namespace document with a default namespace declaration would start matching *all* element with the `foo=""` attribute, rather than just those in the default namespace. This might have an effect on UA stylesheets, tho that can be trivially fixed by switching them to `*[foo]` so they pick up the default namespace. The question is just whether this will have a meaningful effect on web content. For that to happen you need to (a) be using a mixed namespace document, (b) be using a default namespace, (c) have a style rule that doesn't mention tagnames but nevertheless expects to only apply to the default-namespace elements, and (d) have element in the other namespaces that would match that rule. While (a) isn't too uncommon (SVG and MathML are both mixable in HTML, and SVG's `<foreignContent>` lets you introduce HTML/etc), I suspect the other three conditions are *very rare*, both individually and especially in conjuction.

Thoughts?

Please view or discuss this issue at https://github.com/w3c/csswg-drafts/issues/9810 using your GitHub account


-- 
Sent via github-notify-ml as configured in https://github.com/w3c/github-notify-ml-config

Received on Wednesday, 17 January 2024 18:10:48 UTC