Conversation
brijeshb42
commented
Mar 14, 2025
- I have followed (at least) the PR section of the contributing guide.
c1cb8af to
0ba13a9
Compare
| } | ||
| ``` | ||
|
|
||
| In the above example, the color of the text will be `blue` in both the cases because the final generated css will have the styles in the same order - |
There was a problem hiding this comment.
Gotta love stylex for fixing this. It's so counterintuitive that just swapping the position of two global variables affects the behavior of where they are applied. I mean, imagine the following two snippets print a different result.
const a = 5;
const b = 7;
console.log(a / b);
// ---
const b = 7;
const a = 5;
console.log(a / b);There was a problem hiding this comment.
IMO, the correct analogy (in CSS context) here will be
const a = 5;
const b = 7;
console.log(a / b);
// vs
console.log(b / a);Both have different outputs with same order of variable declaration.
Besides, the selling point of stylex is the same as tailwind (when used with something like tailwind-merge), which is atomic css.
This is the main reason due to which, with a runtime check in place, they are able to dedupe the class names based on the property they are targetting and only keep the last class name of a property. So essentially, it applies only one classname for a particular property.
OTOH, Pigment's output is the same as when you'd write CSS modules.
There was a problem hiding this comment.
Both have different outputs with same order of variable declaration.
Exactly, in javascript, the order at call site is important, not at declaration site.
OTOH, Pigment's output is the same as when you'd write CSS modules.
Indeed, that's what's counterintuitive, I'm writing javascript, but I have to keep CSS semantics in mind. The real danger comes when utilities are defined in other files and composed. Now you don't have a module-local record of the order of declaration. You can't even reliably influence it as it may already have been imported somewhere else in a different order.
Besides, the selling point of stylex is the same as tailwind (when used with something like tailwind-merge), which is atomic css.
Sure this is done under the hood with atomic CSS and a lightweight runtime, but I don't think that matters. It's not at all its selling point to me, I don't care how they solve this problem, I care that the semantics match the environment I'm writing in, which is javascript, not css.
There was a problem hiding this comment.
The real danger comes when utilities are defined in other files and composed. Now you don't have a module-local record of the order of declaration. You can't even reliably influence it as it may already have been imported somewhere else in a different order.
We've hit this problem w/ pigment a few times; just want to highlight this problem is real in <5 frontend devs projects, and should be a lot worse when many devs in a project attempt to reuse each others' styles from many different files
| The above example can be extended to imported styles or styled components as well. | ||
|
|
||
| ```tsx title="Button.jsx" | ||
| import { css } from '@pigment-css/react-new'; |
There was a problem hiding this comment.
| import { css } from '@pigment-css/react-new'; | |
| import { styled } from '@pigment-css/react-new'; |
| and then pass in the Pigment CSS configuration options (if any). | ||
|
|
||
| 2. After this, import the `@pigment-css/react-new/styles.css` file in the main entry point file of the app. Make sure that this file is only imported once in the app otherwise you will end up with duplicate styles in the final bundle. | ||
| This import will be responsible for adding the Pigment CSS layer order as well as injecting the css tokens configured in the [theming](/features/theming) section. |
There was a problem hiding this comment.
https://deploy-preview-390--pigment-css.netlify.app/features/theming 404s for me
edit: actually, every page under Theming 404s
There was a problem hiding this comment.
BTW, this PR is in draft mode right now. Not ready for review. I need review for this PR - #367
6d281b6 to
299fe69
Compare
299fe69 to
5d05fb1
Compare
5d05fb1 to
a74d501
Compare
2cc734f to
95c23cf
Compare