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

cases when not unmounting causes render failures in storybook and storyshots #1634

Closed
jrmurad opened this issue Aug 9, 2017 · 2 comments
Closed
Milestone

Comments

@jrmurad
Copy link
Contributor

jrmurad commented Aug 9, 2017

In my decorator, I reset global state to empty with redux.

In each story, I dispatch actions which set the required global data for the component to be rendered.

When I use my browser's refresh while on such a story or go directly to its URL, I get an error page because it:

  1. runs story fine
  2. for some reason, runs the story again
  3. this causes the decorator's reset to run
  4. the reset clears required data from the component so it breaks

I believe the correct thing to do would be to either (a) not run the story twice or (b) unmount first before running again.

Two different hacks got this working for me.

  1. Global decorator with:
    if (typeof document !== 'undefined') {
        ReactDOM.unmountComponentAtNode(document.getElementById('root'));
    }
  1. Removing the guard put in for Action logger breaks stateful components #116

A related issue occurs when using storyshots. The previous story component does not unmount between stories. I was able to fix this by modifying test-bodies.js to unmount. I can submit a PR if this is an appropriate solution.

export const snapshotWithOptions = options => ({ story, context }) => {
  const storyElement = story.render(context);
  const testInstance = renderer.create(storyElement, options);
  const tree = testInstance.toJSON();
  expect(tree).toMatchSnapshot();
  testInstance.unmount();
}

For reference, this is how my stories look:

import {dispatch} from 'store';
import {reset} from 'ducks';

import SomeComponent from 'containers/SomeComponent'

storiesOf('story', module)
    .addDecorator(story => {
        dispatch(reset());
        return story();
    })
    .add('pending removal', () => {
        dispatch(...); // if data set here is required by SomeComponent, we have problems
        return <SomeComponent />;
@ndelangen ndelangen added the bug label Aug 13, 2017
@usulpro usulpro added decorators and removed bug labels Sep 15, 2017
@stale
Copy link

stale bot commented Nov 2, 2017

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. We do try to do some housekeeping every once in a while so inactive issues will get closed after 90 days. Thanks!

@stale stale bot added the inactive label Nov 2, 2017
@jrmurad
Copy link
Contributor Author

jrmurad commented Nov 13, 2017

Note: this is still occurring with 3.3alpha and the same workaround handles it for me.

@stale stale bot removed the inactive label Nov 13, 2017
@danielduan danielduan reopened this Dec 4, 2017
@danielduan danielduan added this to the v3.3.0 milestone Dec 4, 2017
@shilman shilman closed this as completed Jan 2, 2018
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

6 participants