Skip to content
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

Prefix className with propName in development. #739

Closed
mellyeliu opened this issue Oct 10, 2024 · 4 comments
Closed

Prefix className with propName in development. #739

mellyeliu opened this issue Oct 10, 2024 · 4 comments
Assignees
Labels
enhancement New feature or request

Comments

@mellyeliu
Copy link
Member

mellyeliu commented Oct 10, 2024

Describe the feature request

Right now, we hash the <list of “conditions”>++ to generate classNames for everything!
Instead: For common, key-value pairs, such as margin:0, generate small readable classNames, such as: m-0
We'll want to add this in as a config option to StyleXOptions

Some examples:

Margin:0 -> m-0 / `margin-0`
marginTop: 8px -> m-t-8
marginTop: 1rem -> m-t-1rem / `margin-top-1rem`
marginTop: calc(1rem - 2px); -> `m-t-ksjhc` / `margin-top-jksdhjkh`
display: block -> d-block
flex: 1` -> `f-1`
Float: left -> `fl-left`
Filter: saturate() -> `fi-hshjsfg3`

@mellyeliu mellyeliu added the enhancement New feature or request label Oct 10, 2024
@mellyeliu mellyeliu self-assigned this Oct 10, 2024
@necolas
Copy link
Contributor

necolas commented Oct 10, 2024

I wrote a stylex patch in RSD to prefix class names with the prop name: https://github.com/facebook/react-strict-dom/blob/main/patches/%40stylexjs%2Bbabel-plugin%2B0.7.5.patch#L52

I would be wary of trying to generate tailwind-like classes, even if it's only in dev, because people will simply try to write selectors against them. We already had an issue internally where a patch was landed to target a StyleX dev classname.

It was communicated to the CSS BE team that we'd switch to dev data-* props (#723), which would make that a lot less likely for an engineer to try to target with a CSS selector. The GH issue frames it as providing info for a dev tools integration, but it's first an improvement over the current debugging info we generate.

@nmn
Copy link
Contributor

nmn commented Oct 10, 2024

The initial goal is only to make the classes a bit more readable in development. We can start with prefixing class names with the prop name. and leave the hashes for the value part.

@nmn nmn changed the title Add descriptive dev class names Prefix className with propName in development. Oct 10, 2024
@nmn
Copy link
Contributor

nmn commented Oct 10, 2024

See also #184

@mellyeliu
Copy link
Member Author

Done in #742

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or request
Projects
None yet
Development

No branches or pull requests

3 participants