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

Cleaning up CSS Properties with null value #633

Closed
venututor opened this issue Jul 7, 2024 · 3 comments
Closed

Cleaning up CSS Properties with null value #633

venututor opened this issue Jul 7, 2024 · 3 comments
Labels
bug Something isn't working

Comments

@venututor
Copy link

venututor commented Jul 7, 2024

Describe the issue

CSS Properties that are not defined end up in the bundle output. Don't know if its a known issue.

E.g.

{
    boxSizing: 'x9f619',
    borderWidth: 'xmkeg23',
    borderInlineWidth: null,
    borderInlineStartWidth: null,
    borderLeftWidth: null,
    borderInlineEndWidth: null,
    borderRightWidth: null,
    borderBlockWidth: null,
    borderTopWidth: null,
    borderBottomWidth: null,
    borderStyle: 'x1y0btm7',
    borderInlineStyle: null,
    borderInlineStartStyle: null,
    borderLeftStyle: null,
    borderInlineEndStyle: null,
    borderRightStyle: null,
    borderBlockStyle: null,
    borderTopStyle: null,
    borderBottomStyle: null,
    transition: 'xtvu293',
    transitionBehavior: null,
    transitionDelay: null,
    transitionDuration: null,
    transitionProperty: null,
    transitionTimingFunction: null,
    outlineOffset: 'x1cm8ssg',
    transform: 'x1sjarlb',
    $$css: !0,
}

I only defined properties that have class rest are all added to the output.

Expected behavior

It would be great to clean up this unnecessary CSS Properties from the bundle output. This is not affecting any UI or causing issue, its just end up in the final bundle which essentially increases the bundle size.

Steps to reproduce

  1. Rollup
  2. JavaScript(No framework)
  3. @stylexjs/rollup-plugin

I defined stylex CSS with create API and used @stylexjs/rollup-plugin plugin. The output looked like above.

Test case

No response

Additional comments

No response

@venututor venututor added the bug Something isn't working label Jul 7, 2024
@Jta26
Copy link
Contributor

Jta26 commented Jul 7, 2024

Unless I'm mistaken, I think this behavior is intended in order to ensure that the last style always wins. It seems to be setting null here in order to override more specific styles that potentially come from other stylex.create() calls that are passed in.

if you had some styles that define background color

const lessSpecificStyles = stylex.create({
  container: {
    background: 'green',
  },
});

const moreSpecificStyles = stylex.create({
  container: {
    backgroundColor: 'red'
  }
});

Setting these nulls allows you to use the less specific styles last, and still have them apply because lessSpecificStyles.container will set backgroundColor to null when it builds.

stylex([moreSpecificStyles.container, lessSpecificStyles.container]);

I'm not 100% sure if this is the reason though

@necolas
Copy link
Contributor

necolas commented Jul 7, 2024

Change styleResolution to property-specificity. The output will not contain that bloat https://stylexjs.com/docs/api/configuration/babel-plugin/#styleresolution

@necolas necolas closed this as completed Jul 7, 2024
@nmn
Copy link
Contributor

nmn commented Jul 9, 2024

@Jta26 That is exactly the reason for this.

@venututor if you choose property-specificity styles merge the way they do in React Native, so be aware of the change in behaviour.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working
Projects
None yet
Development

No branches or pull requests

4 participants