Comments (6)
We really liked the idea of this RFC and implemented something which works.
Our implementation focuses on @linaria/atomic
. But i guess a similar implementation should be possible with in compiled
as well.
Because both are build time css-in-js libraries which just manipulate the classnames at runtime.
compiled uses the the ax
function and linaria does something similar with a cx
function.
Our implementation should be able to handle the safe and "not safe" cases mentioned in the RFC above by @itsdouges without needing to add additional selectors.
You can checkout this article for more details: https://medium.com/engineering-housing/css-pipeline-housing-com-ab8bc09ee4da
The corresponding implementations for linaria's cx
function and the function to generate classnames can be found here and here
What we haven't been able to solve for though is long-term caching. how to ensure that we get consistent results across builds. We have done an implementation which requires storing the generated classnames in firebase DB. But we would love to do away with that approach. Looking out for suggestions and comments!
from compiled.
Tangent thought: Explicit disabling of composition/conditional CSS. It means when baked we can simplify it down to something tiny.
from compiled.
I'll add an idea for a step in between: having better mapped shorthands for known properties.
For instance, instead of width: 10px
becoming _1p1dangw
, why cannot we make it just _w_10
?
CSS has a limited dictionary and we could provide compact shorthands for the most used properties.
For values, we could expose a babel config to declare the most used unit (px/em/rem/...) and compact those while preserving hashes for all others.
It might not be a massive saving but given how often things like position: relative
, padding-left: Xunit
, ... are used, might have sizeable impact on DOM (even if gzip compression mitigates a lot)
from compiled.
Hey @albertogasparin ,
For values, we could expose a babel config to declare the most used unit (px/em/rem/...) and compact those while preserving hashes for all others.
Can you give an example please?
from compiled.
[
"@compiled/babel-plugin",
{
"parserBabelPlugins": ["typescript", "jsx"],
"mostCommonUnit": "px"
}
]
This is leveraging the fact that projects generally have a recommended unit of measure that most values adopt (usually px or rem). But thinking more about it, in our case with the push for css vars for spacing, we might find very little benefit as most might end up being padding: var(--spacing-xs)
🙈
from compiled.
not really related but vanilla-extract also does this with the identifier option
from compiled.
Related Issues (20)
- Docs: Limitations & runtime styles HOT 3
- Order Media Queries HOT 6
- onFoundStyleRules is not called HOT 1
- Issue with jsx types
- Issue with package.json
- :has(:focus-visible) gives different and unexpected results to &:has(:focus-visible)
- Decide on long-term solution on ampersand in CSS selectors (e.g. `:hover` and `&:hover`) in `styled` and `css` APIs
- Throw clearer error when object property name is imported through barrel files HOT 1
- Support `as const` for object property names
- Next.js 13+ support? HOT 2
- Fails silently when Compiled APIs are used as values in style attribute
- Using object property (imported from CommonJS / CJS package) as media query results in failed build
- When using an object property in a media query, `as const` in the object definition causes build to fail
- Properties fall-through to wrapped DOM element when there are default values in the property declaration
- CSS Map has its output property types unexpectedly expanded at times HOT 1
- Types on `css={…}` don't block using the top-level object from `cssMap()` HOT 1
- Styles are lost after composing styled component and then using `as` prop HOT 1
- Passing a `css` output as a value to another `css` call fails with no type error (etc)
- Object syntax creates unnecessary quotes when using properties like `content: ''`, resulting in style not being applied
- Using css variables in style declarations are always converted to kebab-case
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
D3
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
-
Recommend Topics
-
javascript
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
-
web
Some thing interesting about web. New door for the world.
-
server
A server is a program made to process requests and deliver data to clients.
-
Machine learning
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from compiled.