-
Notifications
You must be signed in to change notification settings - Fork 396
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
CSS @import corrupts scoped CSS #3254
Comments
Btw. just noticed that something similar happens when there is a syntax error instead of const css = `
// CSS comments need to be enclosed in /* */
.foo { color: green; }
`; (In fact, I am currently trying to compile with LESS the CSS rendered by Ractive, and LESS allows simple line comments.) Here is the rendered CSS output which looks pretty, um, interesting to say the least: /* Ractive.js component styles */
/* {e25f538e-07bc-cd9b-7825-014cb8d6d82f} */
// CSS comments need to be enclosed in
.foo[data-ractive-css~="{e25f538e-07bc-cd9b-7825-014cb8d6d82f}"], // CSS comments need to be enclosed in
[data-ractive-css~="{e25f538e-07bc-cd9b-7825-014cb8d6d82f}"] .foo, // CSS comments need to be enclosed in[data-ractive-css~="{e25f538e-07bc-cd9b-7825-014cb8d6d82f}"]
.foo, // CSS comments need to be enclosed [data-ractive-css~="{e25f538e-07bc-cd9b-7825-014cb8d6d82f}"] in
.foo, // CSS comments need to be enclosed[data-ractive-css~="{e25f538e-07bc-cd9b-7825-014cb8d6d82f}"] in
.foo, // CSS comments need to be [data-ractive-css~="{e25f538e-07bc-cd9b-7825-014cb8d6d82f}"] enclosed in
.foo, // CSS comments need to be[data-ractive-css~="{e25f538e-07bc-cd9b-7825-014cb8d6d82f}"] enclosed in
.foo, // CSS comments need to [data-ractive-css~="{e25f538e-07bc-cd9b-7825-014cb8d6d82f}"] be enclosed in
.foo, // CSS comments need to[data-ractive-css~="{e25f538e-07bc-cd9b-7825-014cb8d6d82f}"] be enclosed in
.foo, // CSS comments need [data-ractive-css~="{e25f538e-07bc-cd9b-7825-014cb8d6d82f}"] to be enclosed in
.foo, // CSS comments need[data-ractive-css~="{e25f538e-07bc-cd9b-7825-014cb8d6d82f}"] to be enclosed in
.foo, // CSS comments [data-ractive-css~="{e25f538e-07bc-cd9b-7825-014cb8d6d82f}"] need to be enclosed in
.foo, // CSS comments[data-ractive-css~="{e25f538e-07bc-cd9b-7825-014cb8d6d82f}"] need to be enclosed in
.foo, // CSS [data-ractive-css~="{e25f538e-07bc-cd9b-7825-014cb8d6d82f}"] comments need to be enclosed in
.foo, // CSS[data-ractive-css~="{e25f538e-07bc-cd9b-7825-014cb8d6d82f}"] comments need to be enclosed in
.foo, // [data-ractive-css~="{e25f538e-07bc-cd9b-7825-014cb8d6d82f}"] CSS comments need to be enclosed in
.foo, //[data-ractive-css~="{e25f538e-07bc-cd9b-7825-014cb8d6d82f}"] CSS comments need to be enclosed in
.foo, [data-ractive-css~="{e25f538e-07bc-cd9b-7825-014cb8d6d82f}"] // CSS comments need to be enclosed in
.foo { color: green; } |
The css "parser" is just a bunch of regular expressions so this is not surprising. I think we should aim to make it reliable with valid CSS but that's it, handling syntax errors is a bit too much. If you want to use less, you should definitely compile before applying scoping. Regarding |
Currently, I don’t mind if the CSS would simply be copied as is – just because I am trying postprocessing with LESS and am fully aware of the syntax breaches that could arise. I agree compiling before scoping would be the better approach. However, my first attempts were futile because I could not solve asynchronous issues with the LESS renderer (see less/less.js#3238). You would not have some good idea or further suggestion for me I still could try by any chance? |
I tried to do this some time back but don't remember if I was successful. Eventually I just moved to separate less files because the components files were getting too long and hard to navigate. Now I simply wrap all component styles with |
Thanks for sharing the idea with the component class names, sounds good! |
Description:
Assume the following example:
This renders a green text on a default background and correctly scopes the styles, no issue here:
However, when I add a CSS
@import
directive, e.g. for loading a font, the rendered CSS forbody
suddenly becomes unscoped and thus, the background appears red:In fact, the rendered CSS does not have a scoped body, anymore:
Versions affected:
Platforms affected:
Reproduction:
→ Playground
The text was updated successfully, but these errors were encountered: