question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

css prop not working with utils and variables

See original GitHub issue

Bug report

Describe the bug

Hi, first of all thanks for the library, it’s really great!

We are using Stitches for our design system in a monorepo, but also as a package for our other apps that are not in a monorepo yet. When we use it in a monorepo, it works fine. We are using Turborepo and the design system is just imported via pnpm workspaces. So it is not bundled, just imported.

But when we use it as an npm package via Gitlab package registry in our other repos, we have a problem with the css prop. It just doesn’t transform into correct CSS. We are using vite with the following setup:

import react from '@vitejs/plugin-react';
import path from 'path';
import { defineConfig } from 'vite';
import dts from 'vite-plugin-dts';
import svgrPlugin from 'vite-plugin-svgr';

// https://vitejs.dev/config/
export default defineConfig({
  // Need this empty to generate path "build.js" instead of "/build.js" for minio links
  base: '',
  build: {
    outDir: 'lib',
    lib: {
      entry: path.resolve(__dirname, 'index.ts'),
      formats: ['es'],
      fileName: 'index',
    },
    rollupOptions: {
      // dont bundle react and react-dom, but instead use the external versions
      external: ['react', 'react-dom'],
      output: {
        globals: {
          react: 'React',
          'react-dom': 'ReactDOM',
        },
      },
    },
  },
  envPrefix: '_',
  plugins: [
    // because we use react
    react(),
    // for exporting svgs
    svgrPlugin({
      svgrOptions: {
        icon: true,
      },
    }),
    // for exportig ts types
    dts(),
  ],
});

To Reproduce

Steps to reproduce the behavior, please provide code snippets or a repository:

  1. Use stitches as an npm package
  2. Have a component which can get the css prop
  3. Check CSS in the browser
  4. See that the CSS is not transformed. It doesn’t transform our utils nor our variables, e.g. colors that are defined in the design system. Autocomplete works for the utils, but not for the variables

Expected behavior

utils and variables work as defined in the design system.

Screenshots

marginLeft is ok, because it uses a number, but our util mt for marginTop that uses a variable is not compiled. <IconButton> just passes the css prop to it’s styled div

69b4ae54-695c-4bf2-accc-b3bb0095e2b8

The same is happening for our Box component, which looks like this:

import { styled } from '../../theme/stitches.config';

export const Box = styled('div');

Autocomplete for util property works, but the type is {} | undefined Screenshot 2022-04-28 at 08 55 22

But for the values it doesn’t, probably because the type is {} | undefined as you can see on the previous image Screenshot 2022-04-28 at 08 55 48

But if I use full CSS property, the autocomplete for the values works Screenshot 2022-04-28 at 08 50 16

But in the end neither utils nor the variable values are transformed into CSS Screenshot 2022-04-28 at 08 51 25 Screenshot 2022-04-28 at 08 51 32

For other components that has e.g. color as a prop that uses our variables it works, just the css prop is broken. Is it a bug on your side or are we doing something wrong during build process?

Thanks 🙏

System information

  • OS: 12.3.1
  • Browser:
    • Brave - Version 1.37.116 Chromium: 100.0.4896.127 (Official Build) (arm64)
    • Chrome - Version 100.0.4896.127 (Official Build) (arm64
    • Safari 15.4
  • Version of Stitches: “@stitches/react”: “^1.2.6”
  • Version of Node.js: v14.18.3
  • Vite: v2.8.0

Issue Analytics

  • State:closed
  • Created a year ago
  • Reactions:3
  • Comments:8

github_iconTop GitHub Comments

4reactions
ronaldruzickacommented, Jun 6, 2022

@hadihallak thanks for the hint. The issue probably is babel-plugin-styled-components because we also use Styled Components in older projects, so the generated class is cases-list___StyledButtonDS-sc-qqd2ak-1 gcrzmf.

But on a new Vite project without Styled Components it works properly. I’m closing this issue.

Thanks again! 🙏

1reaction
LexSwedcommented, May 10, 2022

Seems that custom utils types doesn’t match with que theme types

All theme tokens are prefixed with $ sign.

Read more comments on GitHub >

github_iconTop Results From Across the Web

css prop not working with utils and variables #1013 - GitHub
Have a component which can get the css prop; Check CSS in the browser; See that the CSS is not transformed. It doesn't...
Read more >
How to set css variable using react - Stack Overflow
Since you are entering an unknown property, it fails the type check. What you can do is assert the type yourself so this...
Read more >
The css Prop - Emotion
The primary way to style elements with emotion is the css prop. It provides a concise and flexible API to style your components....
Read more >
What I Learned at Work this Week: Stitches | by Mike Diaz
Stitches avoids unnecessary prop interpolations at runtime, making it significantly more performant than other styling libraries. Each CSS ...
Read more >
Stitches — CSS-in-JS with near-zero runtime
Stitches avoids unnecessary prop interpolations at runtime, making it more performant ... smart tokens, css prop, as prop, utils, and a fully-typed API....
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found