-
Notifications
You must be signed in to change notification settings - Fork 25
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
Consider a different name for 'adoptedStyleSheets' #97
Comments
I like it. It mimics the KISS paradigm of : e.classList.add('...') ... which I love to use. In webcomponents, I probably would like to do : this.css.add(sheet); To add global stylesheets, I might do : globalThis.css.add(sheet); |
It's defined here and can be seen in a few APIs such as |
Step 2 from that spec page:
In other words, a node cannot be adopted by multiple parents. It feels like it's being used incorrectly here. |
There is a namespace object named |
Wouldn't |
One thing about "css", is that it specifies the exact technology used today for style sheets. If there were to ever be another styling type, other than CSS (that could be mixed into this array along with css), at that point "css" would become a bad name. I like "styles" (plural) for the name because it reminds me that this is an array of styles even if |
We definitely need some array-like structure for the API, since the underlying semantics are array based. I see the need for these operations:
|
For what it's worth, I think the initial idea was to use |
It's the exact same casing already used in
Legit. Our usage of 'adopted' elsewhere in the platform does indeed imply ownership that's not present here. My original suggestion was, iirc,
lol, good point
I get you, but I really think it's important to keep this name close to the existing
That's not really a big deal here; we're long, long past the point where a new styling language is a particular concern.
Yup, need basically all the functionality of an Array here. If we could convincingly fake an Array on the platform, that would be something else, but we can't. :/ |
As an app developer I would file the following under YAGNI:
I'm also sceptical that I would need to prepend, in practice. I appreciate that there may be some contrived situations in which those operations are necessary, but it doesn't seem to me that the API needs to optimise for them.
I'm not sure I've ever seen anyone use Moreover, |
As someone who maintains code that already uses Managing the list directly is extremely important for app and component-set theming mechanisms and polyfills that might rely on adoptedStyleSheets. Given that multiple actors may be managing the list, being able to tell if the sheets you care about are already in the list, and what precedence they're at is important. |
Hum, so you want to be able to test a key, then decide if you insert before of after this key. |
If the word |
If the acronym is really considered regrettable, |
Why not simply The name is a bit longer than The only thing I dislike about
If I were a developer exploring a new feature called Constructable StyleSheets, I think I would find it intuitive that there is a new attribute called |
Ostensibly this API will be used for CSS modules as well, so |
Just putting some thoughts here, the purpose of this API is to share stylesheets across multiple
|
I think the name should describe what the author intends to do with the stylesheets, not how they were made. One could imagine future ways to create detached stylesheets that don't involve a constructor, but which might still be desirable to attach to a document at some point. So we should not lock in how they are made IMO. I am not sure why adding non-constructed stylesheets is not allowed currently. Is it because all other current ways of making stylesheets already start out attached to a document? In which case the error isn't that it's not constructed, it's that it is already attached. |
I think it's reasonable to not tie the name to how the sheets are created in case that were to change in the future. I am just referring to the spec's description of
|
Alright, I've tired to summarize the list of suggestions made so far with the corresponding concerns.
|
What about something like |
I think that has the same concern mentioned earlier that it sounds not related at all to |
To me the essence of these things are that "each style sheet listed" is in the form of a javascript variable that points directly to the style in memory and NOT some URL that has to be downloaded and cached from a web server. This makes me think of names like:
By now, isn't just going to stay adoptedStyleSheets anyway? Verbosity! I'd be cool with styles, styleSheets, or shadowStyleSheets. |
So long as it's not misleading as to the relationship between the stylesheets and the document/shadow root in a problematic way, I think it's nice that a web component's shadow root ...despite them being slightly different senses of connected. |
Those are different senses of the word connected, I think. |
@othermaciej I disagree. const sheet = new CSSStyleSheet();
someShadowRoot.adoptedStyleSheets = [ sheet ]; // using the old naming convention on purpose here
console.log(sheet.isConnected); // if the feature exists, I would presume this to be true Therefore we can ask to what is |
I don’t think the analogy with node’s connectedness quite works because a single node can be associated with at most one document whereas a style sheet can be associated with multiple shadow trees / documents; this is actually problematic though... We probably want to limit it to the same document somehow. Otherwise we’d end up with global object leaks. |
Hmm... That's not how Chrome's implementation behaves, fwiw. @rakina / @tabatkins, is that intentional? |
(seems a bit weird to me to mix up the two lists of stylesheets like that, fwiw) |
If we make a successor to I don't really have an opinion on which is better, except that it should be specified, and ideally tested by WPT tests. |
It's also possible that I'm misreading the CSSOM or Constructible Style Sheets specs. There's a remote chance that the authors of the spec did not realize that adding to "document or shadow root CSS style sheets" causes the sheets to eb exposed in the |
Maybe we can have it both ways? Throwing other shades of the literary metaphor: So, edit |
@rniwa, According to the spec
Since that definition is specifically about an element, couldn't a |
Having a slightly different semantics for connectedness between nodes and style sheets would be too confusing. |
How about It does not imply the connect state or if is shared or not. Just the scope/locality of the style sheets |
The only real-world analogy for this feature I can think of is when two atoms share an electron and that's just bond. So |
Oops yeah I think we never intended the adopted stylesheets to be included in the |
OK, filed #118 While filing I also noticed a more serious problem with the spec, which is that the spec does not appear to require adopted stylesheets to be used for styling, since that is defined (I think) by CSS Cascading & Inheritence, not by CSSOM. |
I like |
|
re. More generally, regarding the second category in Maciej list, Regarding the priority options, the cascade is something that is often ignored by frontend devs that are primarily coders rather than designers, often to their detriment. Having a salient reminder of the existence cascade in the API name may be a good thing. Edit: |
Good point about The other kinds of styles also apply at the root, even if they originate from a more specific element, so I don't think |
Oh, indeed, not sure why I had erroneously inferred that the new methods were the only one that applied. Naming is both a logical and a UX problem, which turns into bikeshedding contests because programmers are often not trained in the latter. There's a method to UX, and there are objective properties that make a good name beyond pure semantics. Keep in mind that we're toolsmiths here, and that the names are the mental handles for those tools. They should be:
They should also be descriptive, but I think that the description emphasis should be put on the properties that are important for everyday use, not for first time use. That's why I don't like the adjectives. They are vague and ethereal, so they often don't stand on their own. You need to tack on "StyleSheet" for disambiguation. "Put the styles in the extraStyleSheets" vs "... in the epilogue". Using a unique noun roots the the concept in the mental map without redundancy. With all that said,
It is a bit less descriptive (emphasizing the fact that the are out of the DOM tree), but more playful (another important dimension as far as UX goes). This may not be the best name though... The accronym can be easily misused (trigger warning).You could "put the CSS in the SSS", which is clearly better than the current acronym... It would only be one typo away given the QWERTY layout tough. Cue in harassment lawsuits for accidental typos (or actual harassment disguised as oversight). Edit: this took a dark turn, sorry...Edit: That general direction may be worth exploring. |
Ha, along those lines: stylePile. Making it rhyme is a must. |
Another option for a prefix could be
|
- Source Perhaps comparing adoptedStyleSheets to what is above will also help in its renaming. What do you call these dom instantiated style sheets? scriptedStyleSheets? They're called constructed style sheets here: https://wicg.github.io/construct-stylesheets/#modifying-constructed-stylesheets |
assignedStyleSheets ? |
How about something like |
Given this is shipping everywhere it feels like we should consider this issue resolved and close it |
Yup, we're pretty far past the point where this could be changed now. |
It's pretty frustrating that an issue with a preponderance of upvotes is closed after almost 4 years of inactivity because 'oops, too late to do anything about it now'. Of course it's too late to do anything about it now, that's why I raised it in 2019! Things like this are why I and many others don't really consider it worthwhile to engage in the standards process. |
There were many, many suggestions in this thread, but none of them were sufficiently compelling to change the spec to. Note that I engaged in the thread back when you first posted it, and several additional times after that; the implication that this thread was simply ignored and then closed as a fait accompli is not appreciated. An important aspect of engaging in the standards process is realizing that not every good idea will result in change. |
As decided by whom?
Where? You responded on Aug 14 2019, the day I opened the issue, and then again two hours ago to close the issue. I don't see any evidence that you responded to the many perfectly reasonable suggestions in between. If GitHub's UI is somehow hiding additional responses, then I apologise. I'm not stomping my feet saying that every time someone opens an issue it should result in a change. I am saying that when under-designed features get YOLOed into the platform, it reinforces the belief that implementers wield all the power in these discussions. |
Me, the editor. (And no implementor felt sufficiently passionate about it to press for any other name.)
Ah, you're right. I literally just re-skimmed the thread before posting that, and I think just got a little muddled with some of the other commenters.
That is a correct belief, tho. Standards are a means to coordinate implementations to go in the same direction. The goal is implementations agreeing with each other, but that's entirely voluntary on the implementation's part. Everyone who is not an implementor gives input to the process, arguing their position to attempt to convince the editors and implementations to do something in a particular way, but they have no ability to cause change.
And now you're continuing to be offensive, so I'm locking this thread. |
The name
adoptedStyleSheets
is a bit awkward, for a few reasons:It's long
Unwieldy names aren't uncommon in the DOM, but it's particularly problematic when the most common example usage...
...involves repetition. (I'm hopeful that this pattern will be abandoned in favour of explicit methods, due to the fact that it will result in nasty race condition bugs, but it's still a lot to type.)
'Adopted' is confusing
I'm not aware of any other places in the DOM where this verb is used. The most commonly understood meaning of 'adopted' is in the family context, where there's a parent-child relationship. Multiple families cannot adopt the same child. Used here, it could easily be understood to mean that a stylesheet can belong to a single element.
The casing is hard to remember
Although CSS stands for Cascading Style Sheets, people informally talk about 'stylesheets' rather than 'style sheets' — one word. You only ever see
<link rel="stylesheet">
, never<link rel="styleSheet">
. This makes it harder to remember whether it'sadoptedStylesheets
oradoptedStyleSheets
, particularly if you're not writing it frequently.In fact, this is part of a spec called Constructable Stylesheets!
Of course, there is an easy way to remember it, but...
...The acronym is unfortunate
Not that I'm opposed to levity in web development, but I guarantee that this will be universally shortened to 'document dot aSS' or 'this dot aSS'. I'm not sure if that's what everyone had in mind.
Is there a reason this couldn't simply be
document.css
? An API like this would be a lot more palatable to most developers:(I realise there are concerns about being able to control the order of the collection, so
add
andremove
may be too simplistic an API, but I'd expect appending to account for 99% of cases. Regardless, that's a separate issue.)The text was updated successfully, but these errors were encountered: