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

[babel-plugin] Exported Styles that use defineVars cause variables to be left behind in the output #896

Open
abettadapur opened this issue Feb 19, 2025 · 1 comment
Labels
bug Something isn't working

Comments

@abettadapur
Copy link

abettadapur commented Feb 19, 2025

Describe the issue

I have two definitions

  • I have defined typography design tokens using defineVars as follows
export const typography = stylex.defineVars({
    textDisplayFontFamily: 'Roboto,
    textDisplayFontSize: 14,
    textDisplayFontWeight: 600,
    textDisplayLineHeight: '24px',
...
})
  • I have defined shared typography styles that compose these individual tokens. These are exported to be re-used across the application
// stylex-typography.ts
import {typography} from "./tokens.stylex"
export const typographyStyles = stylex.create({
    textDisplay: {
        fontFamily: typography.textDisplayFontFamily,
        fontSize: typography.textDisplayFontSize,
        fontWeight: typography.textDisplayFontWeight,
        lineHeight: typography.textDisplayLineHeight,
    }
})


// component.ts
import {typographyStyles} from "./stylex-typography"

<div {...stylex.props(styles.myDiv, typographyStyles.textDisplay)} />

const styles = stylex.create({
    myDiv: {
        display: 'flex'
    }
})

This setup causes the StyleX transform to leave behind:

  • The result of defineVars
  
__webpack_require__.d(__webpack_exports__, {
typography: () => (typography)
})

const typography = {
  textDisplayFontFamily: "var(--textDisplayFontFamily-x1rwjgsf)",
  textDisplayFontSize: "var(--textDisplayFontSize-x151g8os)",
  textDisplayFontWeight: "var(--textDisplayFontWeight-xyqu3li)",
  textDisplayLineHeight: "var(--textDisplayLineHeight-x1yrn3sf)",
....
}
  • Most surprisingly to me, the result of stylex.create in the consumer
react.createElement("div", {
    ...stylex.props(styles.myDiv, typographyStyles.textDisplay),
});

const styles = {
  myDiv: {
    "test_entry__styles.myDiv": "test_entry__styles.myDiv",
    display: "display-x78zum5",
    $$css: true
  }
};

Questions:

  • Is this behavior expected? Are there significant runtime costs to leave these objects behind in the output?
  • Is there a better way that you would suggest to share composed styles like this without leaving behind objects in the output?

Expected behavior

I at least expected that my consuming component would not leave behind styles just because it is using imported shared styles.

Steps to reproduce

Repros with latest StyleX babel plugin

Test case

No response

Additional comments

No response

@abettadapur abettadapur added the bug Something isn't working label Feb 19, 2025
@necolas necolas changed the title [Question | Bug] Exported Styles that use defineVars cause variables to be left behind in the output [babel-plugin] Exported Styles that use defineVars cause variables to be left behind in the output Mar 6, 2025
@mellyeliu
Copy link
Member

Addressing in #941

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

2 participants