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.

Styled Components not working in a Storybook static build?

See original GitHub issue

Describe the bug We have a Storybook 5.3.3 running perfectly fine in dev mode, components utilizing React 16.8.6, Styled Components 4.4 (also tried the new 5.0) and Typescript 3.7 (with ts-loader 6.2.1).

When built for static deployment, things work fine except no styles get injected into the head, so all components are unstyled. Class names are generated fine, and no errors are thrown. Somehow, it appears that SC fails to work within Storybook’s iframe?

To run the build, tried deploying to Surge as well as npx http-server .out per docs, same result 😦

To Reproduce Yet to repro using a bare-bones project setup… Just curious if it’s a known issue?

Expected behavior Styles should be present inside iframe head’s style tag

Screenshots no-styles

System:

  System
    OS: macOS 10.15.2
    CPU: (8) x64 Intel(R) Core(TM) i7-8569U CPU @ 2.80GHz
  Binaries:
    Node: 8.16.1 - ~/.nvm/versions/node/v8.16.1/bin/node
    Yarn: 1.21.1 - ~/Projects/philo-fe/node_modules/.bin/yarn
    npm: 6.4.1 - ~/.nvm/versions/node/v8.16.1/bin/npm
  Browsers:
    Chrome: 79.0.3945.117
    Firefox: 69.0.3
    Safari: 13.0.4
  npmPackages:
    @storybook/addon-a11y: ^5.3.3 => 5.3.3 
    @storybook/addon-actions: ^5.3.3 => 5.3.3 
    @storybook/addon-knobs: ^5.3.3 => 5.3.3 
    @storybook/addon-viewport: ^5.3.3 => 5.3.3 
    @storybook/react: ^5.3.3 => 5.3.3 

Issue Analytics

  • State:closed
  • Created 4 years ago
  • Comments:11 (3 by maintainers)

github_iconTop GitHub Comments

6reactions
stale[bot]commented, Feb 27, 2020

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!

3reactions
iansan5653commented, Jan 22, 2020

I was able to work around this by disabling “speedy” mode in styled-components by adding the following to my webpack.config.js for Storybook:

const path = require("path");
const webpack = require("webpack");

module.exports = function({config}) {

  config.plugins.push(
    new webpack.DefinePlugin({
      SC_DISABLE_SPEEDY: true
    })
  );

  return config;
};
Read more comments on GitHub >

github_iconTop Results From Across the Web

Error in storybook when using styled-component styling ...
An error occurs if a styling component is included in the styled component in the storybook. import { Flex } from "rebass" export...
Read more >
Adventures with Storybook, TypeScript, and Styled Components
A collection of known issues and workarounds for Storybook with CSF stories, MDX docs, TypeScript, and Styled Components.
Read more >
Setup Storybook - JS.ORG
Render component styles. Storybook isn't opinionated about how you generate or load CSS. It renders whatever DOM elements you provide. But sometimes, things...
Read more >
Tooling - styled-components
If you do not use this plugin and try to server-side render ... plugin while allowing the unejected tooling to handle the Babel...
Read more >
Setting up Storybook with Typescript and Styled Components
... but got storybook working with Typescript and Styled Components.Code: https://github.com/benawad/codeponder/ issues /2Watch at 6pm CT: ht.
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