-
Notifications
You must be signed in to change notification settings - Fork 5k
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
Convert v2 POC styles to CSSNext #4539
Comments
This unfortunately isn't going as well as I had hoped 😐. After working on this for the past two days, I believe we should revise our decision in #4514 on reconsider SASS as our source style language. Reasons below: Emergent specs are less powerful and more subject to change than SCSSSome aspects of CSS4, such as nesting and mixins, are not only less powerful than their sass equivalents (mixins don't take arguments, nesting Furthermore, other transformations are limited by static compilation, such as custom properties only working within the :root scope. The PostCSS plugin ecosystem is young and requires infrastructural investmentMany PostCSS plugins like autoprefixer are mature, maintained, and work great. Many others, however, are immature, buggy, and/or unmaintained. This puts a lot of effort on us to very specifically track versions and invest a lot of time and energy in infrastructure rather than our own codebase.
|
As far as the ecosystem, yes it is immature overall. However, nothing precludes us from using versions that are known to work for our needs and stick to them. Then, when we need something from a newer version we analyze an upgrade. We should be doing this anyways for various reasons, static versions in NPM are better than variable ones. Humans make mistakes and SemVer doesn't work. I think trying to focus on community contributions was an improper way to try and assess the situation. This is a Google project, of course we are going to get some level of willingness from the community no matter what stack we chose. And gauging the "ease" of contribution is also infeasible since that depends upon each contributor's individual experience. We of course can use emergent things in Sass. However, that comes with the cost of everything else Sass allows. Which means we'd need to spend more review time assessing whether X feature of Sass should be used or not to keep the code only as complex as necessary to achieve a given task. The The "readability" is entirely once again dependent upon what we are comfortable with as individuals. And once again, comes down to us forcing ourselves to be judicious with Sass functionality usage in order to maintain good readability. I specifically did not want us using CSSNext for an "easy-mode" because I knew these stack problems would happen. You may require a specific version of CSSNext, but, it does not require a specific version of anything. So random breakage is bound to happen. So far, none of the problems encountered after breaking the problem down have been PostCSS's fault (aside from one issue yesterday which was extremely weird.) It was all syntax mistakes either from conversion or quickly trying to get it done. Today, the biggest issue is the way lerna is doing the internal package structuring. It is proxying the packages and not symlinking their locations. That means, import references of package names in the CSS don't work. We need to hard-code their paths or figure out something else to do instead of using Lerna. |
My top priority would be maturity and stability from the toolchain side and minimizing risk unless the benefits of moving to something new are substantial. In regards to CSSNext, we have, in the past, worked heavily with future-forward standards on the JS side of things, and the reality is that the specs and tools have often been a moving target which has really undermined the promise of "future-proof" code. So I do think we should maintain some healthy degree of skepticism about even specs that appear to be agreed upon and uncontroversial. The lengthy timeline towards actual implementation almost always causes friction. The benefits of PostCSS alone I think would be closely tied to the question of whether it's better to blacklist features or whitelist features. In general, for production-level concerns, I would agree the latter is usually more advantageous. In this case, for whitelisting, features == plugins which means that there will be code variance that needs to be vetted on a per-plugin basis (or at least expect non-uniform breakage). For blacklisting, we imply a somewhat more monolithic approach, in which case the variance reduces to a single project. I don't know the PostCSS community well enough to comment on the quality and track record of its plugins, but I do lean towards Sass as the default and tried-and-true option. If I'm not mistaken, we can fairly easily enforce feature restriction in Sass with appropriate linters. |
@Garbee - all valid points which I'll attempt to summarize and respond to. First in regards to
Let's discontinue the discussion on
I believe this is an inadequate solve. As I've previously mentioned above this leeches time and energy away from fulfilling the actual goal of this project, which is to build best-in-class material design UI components for the universal web platform. Manual versioning maintenance also means the responsibility is solely on us to track not only bug fixes and enhancements to N plugins that we'd use, but it also means tracking the specifications themselves. Consider:
In the case of sass, we either avoid this problem altogether by not using specifications until they at least become W3C Candidate Recommendation, or we make modifications to source files. In the case of postcss, not only will we have to make modifications to source files, but we will have to begin working our way up from the version of I'd like to prevent this scenario as much as possible.
While I agree with the premise I'd argue that popular packages which are depended on heavily are held to the standard of proper semver. Otherwise, users would deem the package as unreliable / unusable, not depend on it, and therefore it would not be popular. I imagine authors of brand new postcss plugins that don't have many dependents and are still in v0.x are less pressured to follow semver than say node-sass. For mature, stable codebases in the JS ecosystem, semver is almost always followed and therefore optimal.
As @rfru mentioned many of these concerns can be immediately addressed by proper use of a linter. sass-lint supports rules for limiting nesting depth, limiting BEM depth, disabling certain selectors, disabling language features, and also supports writing custom rules. In terms of the bigger picture, I think it's important to ask ourselves: why do we want to switch from sass/scss to postcss? Based on our discussions I believe it boils down to three reasons:
While I stand by that this is a lofty goal, we could always do a full migration in the future, once the dust has settled on all of these bleeding-edge specs. Waiting until specs mature to introduce these changes creates a lot less friction than wrestling with them while they're still in flux.
Linters are a big safety. To summarize, I am not convinced that switching to PostCSS from SCSS yields any net benefit given the requirements of this project. |
So, clearly trying to not use Sass at all won't be happening. Why not go halfway and use Sass for what it is, an aid. We can still code using direct CSS custom variables in the source (without some mixin |
That SGTM. It also means as new css features become more standardized, we have the infrastructure in place to switch to them. However we wouldn't be ruling out using things like sass variables, right? Since there's some stuff that may not be appropriate as an exposed CSS custom property (for example |
Yea, we use Sass vars where appropriate (especially when doing math and for things people shouldn't have a real reason to change) and normal CSS vars for things like colors primarily where developers do have a good need to want to change it in the future (possibly client-side as well.) EDIT: To clarify the usage a bit, if it is something we'd |
It looks like you're evaluating the usefulness of stylelint. I hope you don't mind me chiming in on this issue, but over at stylelint we've thought a lot about the safety that linters can provide. Especially when used to (dis)allow certain language features. More recently we've thought specifically about the difficulties of supporting monolithic pre-processors that use non-standard constructs e.g. operators, Our recent thoughts seem pertinent to the issue in hand, and so I figured you might find it helpful (in coming to a decision on this issue) if I expand on these below. I believe that all the style linters available currently lack the ability to blacklist non-standard constructs. I think this problem hasn't been addressed because:
That's the bad news. The good news is that you can build a pretty big safety-net, whichever approach you take. It's currently possible to (dis)allow nearly all of the CSS language features and the SCSS language extensions that use standard CSS constructs (e.g. at-rules and functions) by using following stylelint rules:
Additionally, there are these rules for controlling specificity: And these As an aside, it looks like your using a BEM-based naming convention. We recommend using the As you can see, it is possible to build a hefty safety-net using the rules above, irregardless of whether you choose a CSS approach or use Sass as an aid. Sass language extensions that use standard CSS constructs can be controlled using these rules too. For example, It might be possible to shrink that hole by trying to write a few stylelint plugins that disallow these non-standard constructs e.g. adding Alternatively, you could further explore ways of not using SCSS as an aid. Perhaps, component composition, custom properties, a bit of code duplication would be enough. I don't know enough about your intentions for this project, or the historical hurdles you've overcome by using SCSS, to comment further on this though. There no clear right answer here. The size of the hole will depend on the number of non-standard constructs you allow. And so the benefits of using SCSS as an aid might outweigh the benefits of having no hole in your linter setup. Either way, I figured that detailing the capabilities (and limitations) of stylelint, and other style linters, will help you somewhat in your decision making. Myself, and I suspect anyone else on the stylelint team, would be more than happy to answer any questions you have about stylelint. So please don't hesitate to holler if, for example, you run into any obstacles while configuring it :) |
@jeddy3 thanks for taking the time to write all that up! You are correct that we're evaluating stylelint and it's currently our top choice (thanks for pushing out v7.0.3 this morning btw!). We like it because it is extensible, seems very well maintained, and (unlike tools like sass-lint) is built not only for specific dialects but for general CSS linting as well. I'm currently working on integrating it now as part of #4464 and haven't run into any problems yet (besides the In terms of scss restriction, I actually feel that the blacklisting / whitelisting rules will help us get most of the way there, especially in terms of at-rules and functions. We'll definitely be using the BEM linter as well so thanks for pointing that out to us! |
Fantastic. I hope it goes well.
I agree. I suggest avoiding non-standard CSS constructs (operators, Well, that's all the linting advice I have. Good luck with V2 btw :) |
@traviskaufman yeap, most of W3C specs could not replace Sass. This is why I am still fan of PreCSS. It didn’t give you full Turing complete programming language, but:
What do you think about it? |
You could make CSS build process faster by replacing Also we have very interesting postcss-inline-svg plugin. It inlines SVG and allow you to change SVG colors or other styles. |
Follow-up to #4514
The text was updated successfully, but these errors were encountered: