Storybook-readme: Error when used with Storybook 5.3+

Created on 17 Jan 2020  路  3Comments  路  Source: tuchk4/storybook-readme

When I use storybook-readme with the latest Storybook (5.3.x) I receive the following error.

Cannot read property 'theme' of undefined

TypeError: Cannot read property 'theme' of undefined
    at getParameters (http://localhost:6006/vendors~main.bff5a406979c62ca8ff1.bundle.js:113604:63)
    at wrapper (http://localhost:6006/vendors~main.bff5a406979c62ca8ff1.bundle.js:113334:49)
    at http://localhost:6006/vendors~main.bff5a406979c62ca8ff1.bundle.js:18748:14
    at http://localhost:6006/vendors~main.bff5a406979c62ca8ff1.bundle.js:18762:26
    at http://localhost:6006/vendors~main.bff5a406979c62ca8ff1.bundle.js:18272:21
    at http://localhost:6006/vendors~main.bff5a406979c62ca8ff1.bundle.js:19791:14
    at http://localhost:6006/vendors~main.bff5a406979c62ca8ff1.bundle.js:19792:16
    at wrapper (http://localhost:6006/vendors~main.bff5a406979c62ca8ff1.bundle.js:17745:12)
    at http://localhost:6006/vendors~main.bff5a406979c62ca8ff1.bundle.js:18748:14
    at http://localhost:6006/vendors~main.bff5a406979c62ca8ff1.bundle.js:18762:26

This only appears when I use this addon. On the bright side, I figured out a temporary workaround by using:

addParameters({
  options: { theme: {} }
});

We find the plugin to be very useful for our projects and we appreciate your help!

Most helpful comment

I think I figured it out. I was setting a theme using

const theme = create({
  base: "light",
  brandTitle: "My Brand",
  brandUrl: "https://mybrand.com",
  brandImage: "/logo.png"
});

addons.setConfig({
  theme
});

And it should have been:

addParameters({
  options: {
    theme: create({
      base: "light",
      brandTitle: "My Theme",
      brandUrl: "https://mybrand.com",
      brandImage: "/mylogo.png"
    })
  }});

Also, If no custom theme is set, the error does not appear.

All 3 comments

I'm also getting this error :(

I think I figured it out. I was setting a theme using

const theme = create({
  base: "light",
  brandTitle: "My Brand",
  brandUrl: "https://mybrand.com",
  brandImage: "/logo.png"
});

addons.setConfig({
  theme
});

And it should have been:

addParameters({
  options: {
    theme: create({
      base: "light",
      brandTitle: "My Theme",
      brandUrl: "https://mybrand.com",
      brandImage: "/mylogo.png"
    })
  }});

Also, If no custom theme is set, the error does not appear.

Hi @mcookdev,

but isn't using manager.js the new of customizing the theme in [email protected]? At least this is what is illustrated in the migration guide 5.2.x -> 5.3.x:

If you are setting storybook options in config.js, especially theme, you should migrate it to manager.js (...) This makes storybook load and use the theme in the manager directly. This allows for richer theming in the future, and has a much better performance!

This would mean this is an issue that should be fixed, right?

https://github.com/tuchk4/storybook-readme/blob/master/packages/storybook-readme/src/services/getParameters.js#L16-L18

This is also explained in the new theming documation: https://storybook.js.org/docs/configurations/theming/

Was this page helpful?
0 / 5 - 0 ratings

Related issues

tuchk4 picture tuchk4  路  4Comments

lychyi picture lychyi  路  5Comments

JamesBliss picture JamesBliss  路  5Comments

mktrue picture mktrue  路  3Comments

smrq picture smrq  路  9Comments