-
-
Notifications
You must be signed in to change notification settings - Fork 4.3k
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
Allow to customize the css scope class via compilerOptions.scopeClass
method
#4377
Allow to customize the css scope class via compilerOptions.scopeClass
method
#4377
Conversation
0b2735e
to
8ebc0fe
Compare
compilerOptions.scopeClass
method
Have you taken a look at the potential API described in Rich's comment? I'm not sure what I'd want this option to be called (I'm not particularly thrilled with either |
1facc52
to
d68f723
Compare
I did look at it, but when testing it was always returning I'm also not the biggest fan of
|
689b30d
to
d8b87a1
Compare
|
Is this something that will happen? It's a bit concerning that there are so many outstanding PR's! |
@kaisermann @Conduitry is there any chance of getting this merged - are we just stuck on the naming of the option? I'd suggest Thanks! |
At the very least, allow the ability to change the hard coded prefix |
Just ran into this today and being able to set a stable scope class during compile would be helpful for vite-plugin-svelte. |
I followed some of the links in this discussion and it seems that what's left to do here is update the PR to current and find a suitable name. If it is safe to assume svelte isn't suddenly going to change the scoping implementation away from using css classes, i suggest naming it 'scopeClass' or 'cssScopeClass' . |
I think I like |
d8b87a1
to
66caecd
Compare
@Rich-Harris Done! However, the current implemented Did you mean for it to only receive the |
Thanks for updating this @kaisermann I think filename and component name are good to have. One thing i'm wondering is if it is worth it to pass in the raw styles instead of a precalculated hash and leave hashing completely to the implementation of cssHash. The call of the default hash() function would then happen in the default implementation of cssHash. That way a custom implementation would not have to pay the (arguably not very high) cost of the default css content hash. |
Yeah, that's exactly my reasoning behind my last comment above 🙈. If I remember correctly, the initial idea was to be able to easily customize the "svelte-" prefix. |
this.source = source; | ||
this.ast = ast; | ||
this.filename = filename; | ||
this.dev = dev; | ||
|
||
if (ast.css && ast.css.children.length) { | ||
this.id = `svelte-${hash(ast.css.content.styles)}`; | ||
this.id = get_css_hash({ |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Maybe we should add a saftynet here and warn the user if he is passing in a hash that is none compliant (similar to a11y checks).
I am really looking forward to this being shipped ☺ |
Alternatively: what if compilerOptions: {
filename,
cssHash: ({ hash, name, filename, css }) => {
// default behaviour
return `svelte-${hash(css)}`;
// stable hashes for HMR
return `svelte-${hash(filename)}`;
}
} |
Opened a PR for that: #6026 |
great!. we should check that feeding the hash function a lot of similar strings (iE file paths within the same root) that it doesn't produce collisions. but even if that is the case a custom impl can just ignore the provided hash fn and roll its own. I can't wait to have this released :D |
Closing this since #6026 was merged 🎉 |
Possible implementation for the custom scope class getter discussed in #570.
scopeClass
property to the compiler options which should receive a method with the following signature:({ hash:string, filename hash:string }) => string
scopeClass
method is provided, the compiler uses the default method that returnssvelte-{hash}
If and after this is merged, the docs should be also updated.
Before submitting the PR, please make sure you do the following
npm run lint
!)Tests
npm test
oryarn test
)