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

Global decorators don't work in storyshots when applied in config file #877

Closed
shilman opened this issue Apr 15, 2017 · 9 comments
Closed

Comments

@shilman
Copy link
Member

shilman commented Apr 15, 2017

Issue by chrbala
Thursday Dec 01, 2016 at 07:09 GMT
Originally opened as storybook-eol/storyshots#59


I am using addDecorator for a few context-providing components. It works when I apply them via storiesOf(...).addDecorator, or globally in a story.

However, global decorators seem to be ignored entirely when applied in the config file.

I am using storybook@2.33.1 and storyshots@2.1.0.

@wuzhuzhu
Copy link

+1

tmeasday added a commit to tmeasday/storybook that referenced this issue May 31, 2017
@tmeasday
Copy link
Member

I tried to reproduce this and failed: https://github.com/tmeasday/storybook/tree/issue-877

Here's what I did:

git clone https://github.com/storybooks/storybook
cd storybook
npm install
npm run bootstrap
cd examples/test-cra
npm install

# ensure that the tests pass
CI=true npm test

# change the `src/stories/index.js` file to add a global decorator, cf https://github.com/tmeasday/storybook/commit/03f98117b38e59efe0aa8dc3b181b2ed61fe27d5

# re-ran the test, noticed the snapshot fail w/ expected decorator diffs
CI=true npm test

@chrbala / @wuzhuzhu maybe you can fork my branch above and tweak it to reproduce the problem?

@frenic
Copy link

frenic commented Jun 10, 2017

@tmeasday I've got a similar issue using Styletron.

import React from 'react';
import {addDecorator} from '@storybook/react';
import Styletron from 'styletron-client';
import {StyletronProvider} from 'styletron-react';

const styletron = new Styletron();

addDecorator(story => (
  <StyletronProvider styletron={styletron}>{story()}</StyletronProvider>
));

Everything works fine at first load. But when I change something with HMR it looses context on update and I get "injectDeclaration" is not a function of undefined. With a simple console.log I noticed that the decorator doesn't invoke on HMR update. Maybe that has something to do with it?

@tmeasday
Copy link
Member

Hi @faddee -- this sounds like maybe a different issue (this particular problem has to do with storyshots, so HMR wouldn't have been involved).

Can you maybe open a new issue and if you are able to a reproduction of the bug with Styletron would be amazing!

@frenic
Copy link

frenic commented Jun 11, 2017

@tmeasday Oh, missed the snapshot part. Thanks for clearing that up.

@shilman shilman changed the title Global decorators don't work when applied in config file Global decorators don't work in storyshots when applied in config file Jun 11, 2017
@ktj
Copy link
Contributor

ktj commented Jun 30, 2017

I've added an example to #879

@ntucker
Copy link

ntucker commented Aug 4, 2017

This change breaks HMR for me. I never had a problem with decorators in the past. Anyone have some tips on how to change my config? I just add decorators then load the stories, which is how the docs say to do things...

addDecorator(marketStatusDecorator)

function loadStories() {
  const req = require.context('../js', true, /\.stories\.js$/)
  req.keys().forEach((filename) => req(filename))
}
configure(loadStories, module)

@duro
Copy link

duro commented Aug 8, 2017

I am implementing a decorator exactly as @ntucker describes and using Storyshots. I have one test that sets's up Storyshot, and it looks like this:

src/components/__tests__/Storyshots.test.js:

import initStoryshots from '@storybook/addon-storyshots'

initStoryshots()

That's it. The rest of my config is all contained in .storybook/config.js, which looks like this:

import { configure, addDecorator } from '@storybook/react'

import Decorator from './decorator'

const req = require.context('../src/components', true, /story.js$/)

addDecorator(Decorator)

const loadStories = () => {
  require('./Welcome/story')
  req.keys().forEach(filename => req(filename))
}

configure(loadStories, module)

I get the error: Global decorators added after loading stories will not be applied and it seems HMR is not working quite right.

@usulpro
Copy link
Member

usulpro commented Sep 15, 2017

Looks like we need to reopen it or create a new one issue?

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

8 participants