-
-
Notifications
You must be signed in to change notification settings - Fork 4.5k
use base 36 for style classes #1192
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
Conversation
Codecov Report
@@ Coverage Diff @@
## gh-1118 #1192 +/- ##
========================================
Coverage 91.67% 91.67%
========================================
Files 126 126
Lines 4575 4575
Branches 1501 1501
========================================
Hits 4194 4194
Misses 158 158
Partials 223 223
Continue to review full report at Codecov.
|
Is |
It can be falsy if you're using the compiler directly. It defaults to 'svelte'... Line 280 in 1ad28e6
...but in the tests, |
Oh ok cool. Yeah I saw that line in the PR, but I wasn't actually sure that it did anything, because I had forgotten the |
when looking into style issues with numerous nested components and cascade:false I found it difficult to understand where the styles came from. Therefore +1 |
It's an interesting tradeoff removing
I was recommending something greater than base 9 and all of these meet the mark! However, you might also consider a counter instead of a hash given the additional scoping from the new component name prefix. My hunch is this would reduce the size of style transmission without losing any additional readability. |
I was thinking that as a follow-up to this PR, maybe it could be entirely user-configurable: const counts = {};
const incr = id => {
if (!counts[id]) counts[id] = 0;
return counts[id] += 1;
};
const { code, css, map } = svelte.compile(source, {
class: ({ name = 'svelte', filename, hash }) => `${name}-${incr(name)}`
}); That way we'd still get the correctness-guaranteeing behaviour ( Separately, it occurred to me that there's another reason not to use |
Agree completely. Nice followup and sets a good precedence for overridable defaults.
I see this as another reason to support overridable defaults for this case. Most implementations would be well suited by Reusable styles (ie CSS Blocks or Atomic CSS) would be a nice future step for something like Sapper. |
Sorry if I am missing something, but where do I put this code in order for it to work? |
Nowhere, it's not supported yet - it was just an idea for a future feature. |
This replaces
svelte-123456
withfoo-2n9c
, wherefoo
is the name of the component.A couple of thoughts:
foo-
instead ofsvelte-
is useful in that you can more easily see which component an element/style belongs to, but it's presumably less compressable. (Also, probably not important but I've heard of people discovering Svelte because they saysvelte-123456
attributes in someone's markup...)