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.

integrating theme-ui with storybook in a gatsby project

See original GitHub issue

Hi,

I have a gatsby project where I have integrated theme-ui. Now i am trying to incorporate storybook in the project so I can develop a component library for my project.

I want my components to rely on theme-ui and the sx prop for styling but when i write stories, they render in the storybook UI without the style applied.

I am a bit lost on how to debug this.

this is what the relevant portion of my .storybook/config.js file looks like

import { configure, addDecorator } from '@storybook/react';
import React from 'react'
import { ThemeProvider } from 'theme-ui'
import theme from '../src/gatsby-plugin-theme-ui/index'

// automatically import all files ending in *.stories.js
const req = require.context('../stories', true, /\.stories\.js$/);
function loadStories() {
  req.keys().forEach(filename => req(filename));
}

addDecorator((story) => (
  <ThemeProvider theme={theme}>
    {story()}
  </ThemeProvider>
))

configure(loadStories, module);

Any help on where to start debugging this are appreciated.

Issue Analytics

  • State:closed
  • Created 4 years ago
  • Comments:21 (7 by maintainers)

github_iconTop GitHub Comments

16reactions
theomjonescommented, Mar 23, 2021

I managed to fix this with the below main.js storybook config. As @hasparus says you can force storybook to use emotion 11. Everything seems chill from what I can see!

const path = require('path')

const resolve = (p) => path.join(process.cwd(), p)

module.exports = {
    webpackFinal(config) {
        config.resolve.alias = {
            ...config.resolve.alias,
            "@emotion/core": resolve("node_modules/@emotion/react"),
            "@emotion/styled": resolve("node_modules/@emotion/styled"),
            "emotion-theming": resolve("node_modules/@emotion/react"),

        };
        return config;
    },
    // .. rest of config
};

Such a sneaky issue

2reactions
hasparuscommented, Mar 23, 2021

@theomjones There are two Emotion contexts. Emotion 11 and Emotion 10. You need to either downgrade Theme UI to 0.3.5, enforce Emotion version with Yarn resolutions and webpack aliases in Storybook’s config or upgrade Storybook to a version that depends on Emotion 11 if it exists (PR here: https://github.com/storybookjs/storybook/pull/13300)

Read more comments on GitHub >

github_iconTop Results From Across the Web

Visual Testing with Storybook | Gatsby
With it, you can visualize different states of your UI components and develop them interactively.
Read more >
Integrating React Storybook into a Gatsby site - YouTube
Broadcasted live on Twitch -- Watch live at https://www.twitch.tv/irreverentmike.
Read more >
Integrating Gatsby, Tailwind, and Storybook - Roman Sorin
A guide to the quick and easy setup of Storybook/Tailwind within Gatsby – two tools that are super helpful and valuable to development...
Read more >
Integrations | Storybook: Frontend workshop for UI development
Integrate your tools with Storybook to connect workflows and unlock advanced ... Link stories together to build demos and prototypes with your UI...
Read more >
Getting Started with Gatsby - Theme UI
To use Theme UI with Gatsby, install and use gatsby-plugin-theme-ui . ... Add the plugin to your gatsby-config.js . ... Create a theme...
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