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.

Global addDecorator not loaded

See original GitHub issue

I see you already trying to solve this issue here #879 but I experiencing maybe the same. I haven’t digged into deeply but following code making issue.

import withThemes from './decorators/withThemes';
...
const spread = require.context('../app', true, /stories.jsx?$/);
...
addDecorator(withThemes);
...
function loadStories() {
  spread.keys().forEach(filename => spread(filename));
}

configure(loadStories, module);

Error is following…

[withTheme] Please use ThemeProvider to be able to use withTheme
      
      at WithTheme.componentWillMount (node_modules/styled-components/lib/hoc/withTheme.js:63:15)
      at node_modules/react-test-renderer/lib/ReactCompositeComponent.js:348:23
      at measureLifeCyclePerf (node_modules/react-test-renderer/lib/ReactCompositeComponent.js:75:12)
      at ReactCompositeComponent.performInitialMount (node_modules/react-test-renderer/lib/ReactCompositeComponent.js:347:9)
      at ReactCompositeComponent.mountComponent (node_modules/react-test-renderer/lib/ReactCompositeComponent.js:258:21)
      at Object.ReactReconciler.mountComponent (node_modules/react-test-renderer/lib/ReactReconciler.js:46:35)
      at ReactCompositeComponent.performInitialMount (node_modules/react-test-renderer/lib/ReactCompositeComponent.js:371:34)
      at ReactCompositeComponent.mountComponent (node_modules/react-test-renderer/lib/ReactCompositeComponent.js:258:21)
      at Object.ReactReconciler.mountComponent (node_modules/react-test-renderer/lib/ReactReconciler.js:46:35)
      at mountComponentIntoNode (node_modules/react-test-renderer/lib/ReactTestMount.js:55:31)
      at ReactTestReconcileTransaction.TransactionImpl.perform (node_modules/react-test-renderer/lib/Transaction.js:140:20)
      at batchedMountComponentIntoNode (node_modules/react-test-renderer/lib/ReactTestMount.js:69:27)
      at ReactDefaultBatchingStrategyTransaction.TransactionImpl.perform (node_modules/react-test-renderer/lib/Transaction.js:140:20)
      at Object.ReactDefaultBatchingStrategy.batchedUpdates (node_modules/react-test-renderer/lib/ReactDefaultBatchingStrategy.js:62:26)
      at Object.batchedUpdates (node_modules/react-test-renderer/lib/ReactUpdates.js:97:27)
      at Object.ReactTestMount.render [as create] (node_modules/react-test-renderer/lib/ReactTestMount.js:125:18)
      at Object.test (node_modules/@storybook/addon-storyshots/dist/test-bodies.js:26:44)
      at Object.<anonymous> (node_modules/@storybook/addon-storyshots/dist/index.js:141:21)
      at process._tickCallback (internal/process/next_tick.js:103:7)

I’m using styled-components which expecting that I will use with HOC from this is quiet straightforward that hoc is not able to gather context data properly.

Issue Analytics

  • State:closed
  • Created 6 years ago
  • Comments:8 (2 by maintainers)

github_iconTop GitHub Comments

2reactions
usulprocommented, Aug 28, 2017

@creaux did you try to put addDecorator inside loadStories() as a workaround:

function loadStories() {
  addDecorator(withThemes);
  spread.keys().forEach(filename => spread(filename));
}
1reaction
usulprocommented, Aug 29, 2017

@creaux I tried to reproduce with @storybook/react v3.2.8 such a simple global decorator:

addDecorator(storyFn => <div style={{border: 'solid 10px navy'}} children={storyFn()} />);

and it works fine for me. What version of Storybook do you use at this moment? Could you try to add this line into your config.js and check it out? Please, make sure that you manually update the page after each change since HMR doesn’t do it for a config files.

Read more comments on GitHub >

github_iconTop Results From Across the Web

Global addDecorator is ignored · Issue #10677 - GitHub
Describe the bug In my React/TypeScript app if I add a global addDecorator in my preview.tsx this is ignored. The exact same decorator...
Read more >
How to add a global decorator in Storybook - Stack Overflow
Edit storybook/index.js, by using addDecorator on it. Example: import React from 'react' import { getStorybookUI, configure, addDecorator } ...
Read more >
Decorators - Storybook - JS.ORG
A decorator is a way to wrap a story in extra “rendering” functionality. Many addons define decorators to augment your stories with extra...
Read more >
Storybook Decorators for Angular - Medium
Apply your decorator to a story. Storybook parameters can be set at the level of a single story, a group of stories (a...
Read more >
How to build a Storybook addon - Chromatic
loading. Varun Vachhar. Nov 13, 2020 — @winkerVSbecks ... Globals represent the “global” (as in not story-specific) context in Storybook.
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