JesusTheHun / storybook-addon-remix-react-router

Use your app router in your stories. A decorator made for Remix React Router and Storybook
Apache License 2.0
50 stars 12 forks source link

Decorators placed after withRouter are called twice #60

Closed eloiqs closed 8 months ago

eloiqs commented 10 months ago

Consider this code sample

export default {
  title: 'Demo',
  component: Demo,
  decorators: [
    (Story) => {
      console.log('Provider');
      return (
        <Provider store={mockStore()}>
          <Story />
        </Provider>
      );
    },
    (...args) => {
      console.log('withRouter');
      return withRouter(...args);
    },
  ],
}

export const Default = {
  decorators: [
    (Story) => {
      console.log('story');
      return <Story />;
    },
  ],
};

Output:

withRouter
Provider
story
Provider
story

Is this how withRouter is supposed to work?

JesusTheHun commented 10 months ago

Have you try the same code outside of storybook to see if it behaves the same way ?

eloiqs commented 10 months ago

No but I'm not sure how that would be relevant as the code outside storybook renders the whole app and doesn't have any storybook decorators, and it is the decorator that is called twice, not the component?

JesusTheHun commented 9 months ago

@eloiqs the array of decorators is just a component tower. The router decorator uses react hooks, therefore in dev mode, they will be called twice, eventually rendering twice.

Can you describe your issue down the line ?

JesusTheHun commented 8 months ago

I'm closing this as no further information has been delivered and no actual issue has been identified. Feel free to re-open this if you have additional information.