-
-
Notifications
You must be signed in to change notification settings - Fork 4.4k
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
RFC: Scoped Style Attribute #901
Comments
nope, right place! I definitely hear you, though it feels like disabling scoping by default is the wrong solution. Or rather, disabling scoping would be the right solution if we wanted to be able to disable scoping, but not for the sake of a side-effect of doing so — because we don't want to! (At least, I don't think we do?) If Which prompts two further questions:
I believe the answer to 1 is 'not very'. Bytes-wise, although the selectors themselves don't compress well, you only have one unique selector per component so I'd expect the post-gzip impact to be acceptable. Perf-wise, there's definitely a theoretical hit, but what kind of numbers are we talking about? (Genuine question!) As for 2, the answer is, well... maybe? For example if we analysed your entire component tree, we could generate efficient Styletron-style selectors and replace classes accordingly (gets slightly tricky with dynamic classes, but still possible). That has one major downside which is that your original classes would vanish (follow me on Twitter for occasional rants about why that's bad...), but if it's an opt-in for perf-heads like you then I'd be okay with it 😀 These are just my thoughts though, I would be interested to know what others think. |
just an idea... how about going the opposite way, i.e: so we keep current behaviour and add unscoped styles if needed, by declaring them explicitly? |
Cool, thanks!
I tend to disagree. I think it's a matter of documentation. The ability to
My inclination is to still go with the I also like @ekhaled's idea, but would like The important part, to me, is just having a simple, straightforward way to turning it off, aside from just avoiding |
Another option is to just call the attribute |
This seems to be the same issue as #1080 (which I closed, since this conversation was already in progress). |
I totally agree with @lukeed |
The global style could also be used to allow @media, @page or @font-face in css. So instead of just a component with some visual attributes components could also be used to add style to a page. |
is there currently a way keep scoped styles for a css classname that is dynamic and is on the same element?
resulting in at the moment you can only do it without the space
resulting in syntax like this might also be handy.
|
@cssandstuff This might be edging on "offtopic" territory, not sure 😉. But, I think you may be after |
@cssandstuff not sure I understand what result you're looking for (i.e. what CSS should be generated)? Some compound selectors will look wacky inside |
Grouping leaky styles together would make things cleaner. <style>
@document { /* No highlighting support for @global */
.btn>.icon {}
.btn>.icon:hover {}
}
</style> |
For anyone following along at home, there’s this RFC which is just in the beginning stages and has not PR yet: https://github.com/arxpoetica/rfcs/blob/css-in-html/text/0000-css-in-html.md |
I'm curious about this myself. In Pinafore, I wrote a script to make all CSS global because I wanted to get rid of the extra attribute selectors, but now that attribute selectors are gone (#1118) it's worth revisiting. I built Pinafore with and without the globalizing, and the total size of all CSS (35 files) increased from 41372 bytes to 48672 bytes (41.3kb -> 48.6kb, +17.6%). So not an enormous increase. Probably more interesting would be to measure the impact on style calculation costs, but this is going to vary heavily from app to app (e.g. how much layout thrashing you may be doing, how complex your DOM is) and from browser to browser. |
I used @maxmilton 's code and created this preprocessor which will make any css code global including support for external files and postcss plugins: |
I have a solution for sass/scss with the https://github.com/ctx-core/ctx-core/blob/master/packages/sass/svelte.js#L34 |
Closing this in favour of the RFC that is open, and because support for global is available via preprocessors, and also, we've discussed a lot that scoping a style tag is not the approach we want. Focus should be shifted to the RFC |
If this is the wrong place for this -- sorry! StackOverflow didn't seem like the right place to me.
Currently, the inclusion of any CSS within a
style
tag is considered scoped. The only way out of this is to wrap your selector(s) in:global()
. This, however, gets to be fairly verbose when you want to wrap all selectors on the page.Arguably, the appeal of SFCs is encapsulating all component-relatives into the single file. Additionally, a core motivation of Svelte (imo) is to assist in the creation of vanilla apps (including HTML, CSS, JS) in a nicer, faster way. (We all know this, duh!)
I bring this up because, right now, devs are essentially penalized for using the SFC format --- the obvious format for Svelte --- with an additional 17 bytes of CSS per selector, and the only ways to avoid the penalty are cumbersome: keep all CSS in a
styles/
dir or:global
all the things.Proposition
I'd like to use Vue as inspiration & move the current behaviors under the
scoped
attribute for thestyle
tag. Nothing would change, including the ability to "exit" the scope with the help of:global
.Then, without
scoped
, Svelte would treat normalstyle
contents as partial CSS files. By default, no "penalties" via bytes (& render time, lol) are suffered. Instead, Svelte concatenates the stylesheet, as is, via component assembly.This also opens the door for CSS preprocessors down the road via the
lang
attribute... another hat tip to Vue.The text was updated successfully, but these errors were encountered: