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

Storybook + Chakra UI V1 not displaying styles #13114

Closed
MariuzM opened this issue Nov 14, 2020 · 20 comments
Closed

Storybook + Chakra UI V1 not displaying styles #13114

MariuzM opened this issue Nov 14, 2020 · 20 comments

Comments

@MariuzM
Copy link

MariuzM commented Nov 14, 2020

Describe the bug
With the new version of Chakra UI v1 storybook has stoped displaying styles, when doing yarn storybook it loads the page but does not display the styles.

Old version:
Screen Shot 2020-11-14 at 08 42 09
Screen Shot 2020-11-14 at 08 41 04

New version
Screen Shot 2020-11-14 at 08 42 00
Screen Shot 2020-11-14 at 08 43 46
Screen Shot 2020-11-14 at 08 44 26

Component
Screen Shot 2020-11-14 at 08 41 12

@shilman
Copy link
Member

shilman commented Nov 15, 2020

Do you have a repro repo you can share?

@MariuzM
Copy link
Author

MariuzM commented Nov 15, 2020

Here you go, it's all standard install https://github.com/MariuzM/bug_testing

@ivan-dalmet
Copy link

ivan-dalmet commented Nov 15, 2020

Same problem here (https://github.com/ivan-dalmet/start-ui)
I think it's the emotion 11. But no idea how to fix it :/

@ghost
Copy link

ghost commented Nov 16, 2020

Same problem in a project with NextJS + Typescript + Chakra UI + Storybook.

@khanhleemtp
Copy link

Same problem

@lee-reinhardt
Copy link

I was able to work around this by implementing a custom webpackFinal config:
chakra-ui/chakra-ui#2527 (comment)

@MariuzM
Copy link
Author

MariuzM commented Nov 20, 2020

Any updates on getting this fixed?

@shilman shilman added the P1 label Nov 21, 2020
@shilman
Copy link
Member

shilman commented Nov 21, 2020

@MariuzM PRs welcome!

@cloud-walker
Copy link

The fix should be to upgrade emotion to v11?

"@emotion/core": "^10.1.1",

@shilman shilman self-assigned this Dec 10, 2020
@shilman shilman added this to the 6.2 maintenance milestone Dec 10, 2020
mwilliamson added a commit to mwilliamson/virtual-hand-signals that referenced this issue Mar 4, 2021
The theming from Chakra UI isn't working correctly due to some
interaction between Storybook and Chakra UI both using Emotion:

    storybookjs/storybook#13114
    chakra-ui/chakra-ui#2527
@SyedUmerHasan
Copy link

This issue is also happening with other libraries as well.
Can someone mention its root cause?

@florianmartens
Copy link

Same here.

@Cretezy
Copy link

Cretezy commented May 22, 2021

Here is the solution that worked for me:

module.exports = {
  stories: ["../src/**/*.stories.mdx", "../src/**/*.stories.@(js|jsx|ts|tsx)"],
  addons: ["@storybook/addon-links", "@storybook/addon-essentials"],
  webpackFinal: async (config) => {
    return {
      ...config,
      resolve: {
        ...config.resolve,
        alias: {
          ...config.resolve.alias,
          "@emotion/core": "@emotion/react",
          "emotion-theming": "@emotion/react",
        },
      },
    };
  },
};

@lakshmimani
Copy link

Here is the solution that worked for me:

module.exports = {
  stories: ["../src/**/*.stories.mdx", "../src/**/*.stories.@(js|jsx|ts|tsx)"],
  addons: ["@storybook/addon-links", "@storybook/addon-essentials"],
  webpackFinal: async (config) => {
    return {
      ...config,
      resolve: {
        ...config.resolve,
        alias: {
          ...config.resolve.alias,
          "@emotion/core": "@emotion/react",
          "emotion-theming": "@emotion/react",
        },
      },
    };
  },
};

This worked for me

@agamm
Copy link

agamm commented Aug 28, 2021

Here is the solution that worked for me:

module.exports = {
  stories: ["../src/**/*.stories.mdx", "../src/**/*.stories.@(js|jsx|ts|tsx)"],
  addons: ["@storybook/addon-links", "@storybook/addon-essentials"],
  webpackFinal: async (config) => {
    return {
      ...config,
      resolve: {
        ...config.resolve,
        alias: {
          ...config.resolve.alias,
          "@emotion/core": "@emotion/react",
          "emotion-theming": "@emotion/react",
        },
      },
    };
  },
};

Maybe npx sb init can check for chakraui and add this (working) fix automatically?

@anilanar
Copy link

anilanar commented Oct 6, 2021

Slight modification, @Cretezy's solution did not work for me. I had to add @emotion/styled to aliases but because there are multiple @emotion/styled versions present, I used absolute paths to make sure it refers to the correct one:

const path = require('path');

module.exports = {
  stories: ['../stories/**/*.stories.@(ts|tsx|js|jsx)'],
  addons: ['@storybook/addon-links', '@storybook/addon-essentials'],
  webpackFinal: async (config, { configType }) => {
    return {
      ...config,
      resolve: {
        ...config.resolve,
        alias: {
          ...config.resolve.alias,
          '@emotion/core': path.resolve(
            __dirname,
            '../node_modules/@emotion/react'
          ),
          'emotion-theming': path.resolve(
            __dirname,
            '../node_modules/@emotion/react'
          ),
          '@emotion/styled': path.resolve(
            __dirname,
            '../node_modules/@emotion/styled'
          ),
        },
      },
    };
  },
};
  

Make sure that node_modules/@emotion/styled is v11, not v10.

@rrsai
Copy link

rrsai commented Dec 3, 2021

After much debugging of the clash between versions of emotion used in storybook and in app, and for those who come after me, I found that storybook has now provided a feature flag to avoid clashing with later versions of emotion: https://github.com/storybookjs/storybook/blob/next/MIGRATION.md#emotion11-quasi-compatibility

@MariuzM
Copy link
Author

MariuzM commented Dec 3, 2021

I think web is going to start moving to https://stitches.dev/ :D

@stale
Copy link

stale bot commented Jan 9, 2022

Hi everyone! Seems like there hasn't been much going on in this issue lately. If there are still questions, comments, or bugs, please feel free to continue the discussion. Unfortunately, we don't have time to get to every issue. We are always open to contributions so please send us a pull request if you would like to help. Inactive issues will be closed after 30 days. Thanks!

@stale stale bot added the inactive label Jan 9, 2022
@shilman
Copy link
Member

shilman commented Feb 1, 2022

FYI, we'll hopefully have a proper fix out this week.

@shilman
Copy link
Member

shilman commented Feb 1, 2022

Boo-yah!! I just released https://github.com/storybookjs/storybook/releases/tag/v6.5.0-alpha.31 containing PR #17000 that references this issue. Upgrade today to the @next NPM tag to try it out!

npx sb upgrade --prerelease

Closing this issue. Please re-open if you think there's still more to do.

@shilman shilman closed this as completed Feb 1, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests